将文件转换成字符串

来源:互联网 发布:帝国cms tags伪静态 编辑:程序博客网 时间:2024/06/11 05:24

/// <summary>
    
/// 将文件转换成字符串
    
/// </summary>
    
/// <param name="path"></param>
    
/// <param name="isSpace"></param>
    
/// <returns></returns>
    public static string GetTempleContent(string path)
    {
        
string result = string.Empty;
        
string sFileName = HttpContext.Current.Server.MapPath(path);
        
if (File.Exists(sFileName))
        {
            
try
            {
                
using (StreamReader sr = new StreamReader(sFileName))
                {
                    result 
= sr.ReadToEnd();
                }
            }
            
catch
            {
                result 
= "读取模板文件(" + path + ")出错";
            }
        }
        
else
        {
            result 
= "找不到模板文件:" + path;
        }
        
return result;
    }

原创粉丝点击