导航

生成静态页面

Posted on 2006-05-28 09:37    阅读(85)  评论(0)    收藏  举报
/// <summary>
/// 读文件
/// </summary>
/// <param name="Path"></param>
/// <returns></returns>

public string ReadFile(string Path)
{
StringBuilder htmltext 
= new StringBuilder();

try 
{
string tempPath = HttpContext.Current.Server.MapPath(Path);
using (StreamReader sr = new StreamReader(tempPath,Encoding.GetEncoding("gb2312")))
{
String line;
while ((line = sr.ReadLine()) != null
{
htmltext.Append(line);
}

sr.Close();
}

}

catch 
{
}

return htmltext.ToString();
}


/// <summary>
/// 写文件
/// </summary>
/// <param name="Path"></param>
/// <param name="Content"></param>

public void WriteFile(string Path,string Content)
{
try
{
string path = HttpContext.Current.Server.MapPath(Path);
using(StreamWriter sw=new StreamWriter(path,false,System.Text.Encoding.GetEncoding("GB2312")))
{
sw.WriteLine(Content);
sw.Flush();
sw.Close();
}

}

catch

}

}