All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
ASP.NET写文件

Writer: qq Article type: Programming skills(编程技巧) Time: 2014/7/9 1:39:32 Browse times: 270 Comment times: 0

ASP.NET写文件


Head photo

Go homepage
Upload pictures
Write articles

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





There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.