Go homepage(回首页) Upload pictures (上传图片) Write articles (发文字帖)
The author:(作者)qqpublished in(发表于) 2014/7/9 1:39:32 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
赞