将文件转换成字符串,常用于读取网站模板

来源:互联网 发布:网络最红女主播是谁 编辑:程序博客网 时间:2024/05/22 00:09
    /// <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;    }

0 0
原创粉丝点击