#region 写入文件 如果存在该文件就递加,如果不存在就新建
/// <summary>
/// 写入文件
/// </summary>
/// <param name="Path">文件路径</param>
/// <param name="content">文件内容</param>
//调用示例
//string webRootPath = _hostingEnvironment.WebRootPath; //获取相对路径
//string strUploadPath = webRootPath + "/Document/";
//string fileLogName = "错误日志" + DateTime.Now.ToLongDateString() + "Log.txt";
//WriteFile(strUploadPath + fileLogName, "测试内容");
public static void WriteFile(string path, string content)
{
if (!System.IO.File.Exists(path))
{
System.IO.FileStream f = System.IO.File.Create(path);
f.Close();
}
System.IO.StreamWriter f2 = new System.IO.StreamWriter(path, true, System.Text.Encoding.GetEncoding("gb2312"));
f2.WriteLine(content);
f2.Close();
f2.Dispose();
}
#endregion
|