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

/// <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;
    }

相关文章:

  • 2021-11-09
  • 2022-12-23
  • 2021-12-11
  • 2021-05-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-18
  • 2022-12-23
  • 2021-06-12
相关资源
相似解决方案