public static bool WriteFile(string filePath, string fileName, string content)
{
FileStream fs = null;
string fileUrl = MergePath("/", new string[] { filePath, fileName });
string physicalPath = HttpContext.Current.Server.MapPath(fileUrl);
try
{
CreateDirectory(HttpContext.Current.Server.MapPath(filePath));
if (FileExists(fileUrl))
{
fs = new FileStream(physicalPath, FileMode.OpenOrCreate, FileAccess.Write);
}
else
{
fs = new FileStream(physicalPath, FileMode.Append, FileAccess.Write);
}
StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
sw.WriteLine(content);
sw.Flush();
sw.Close();
}
catch (Exception ex)
{
LogHelper.Error("關注被動回覆生成txt文件失敗,異常:" + ex);
}
finally
{
fs.Close();
}
if (FileExists(fileUrl))
{
return true;
}
return false;
}