/// <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;
}
将文件转换成字符串
本文介绍了一个实用的方法,用于将指定路径的文件内容读取并转换为字符串。此方法首先检查文件是否存在,然后使用 StreamReader 类来读取文件内容,并返回整个文件内容作为字符串。如果过程中出现错误或文件不存在,则会返回相应的错误消息。

被折叠的 条评论
为什么被折叠?



