ASP.NET写文件
#region 写文件
///
/// 写文件
///
/// 文件内容
/// 文件名字
/// 文件路径
///
public bool WriteFile(string strContent, string strFileName, string strFilePath)
{
bool blnSuccess;
StreamWriter sw = null;
string strToPath = Path.GetFullPath(strFilePath);
//判断目录是不是存在
if (!Directory.Exists(strToPath))
{
Directory.CreateDirectory(strToPath);
}
Encoding ecdFileCode = Encoding.GetEncoding("gb2312");
// 写文件
try
{
sw = new StreamWriter(strToPath + "/" + strFileName, false, ecdFileCode);
sw.Write(strContent);
sw.Flush();
blnSuccess = true;
}
catch
{
blnSuccess = false;
throw;
}
finally
{
sw.Close();
}
return blnSuccess;
}
#endregion