110,535
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 文件写入
/// </summary>
/// <param name="UserID"></param>
/// <param name="fileName"></param>
/// <param name="htmlCode"></param>
private static void CreateFile(string UserID, string fileName, string htmlCode)
{
fileName += fileName.IndexOf(".html") != -1 ? "" : ".html";
string localPath = "E:/DotNet/Sun/SunDecorativeSystem/Users/" + UserID;
if (!Directory.Exists(localPath))
{
Directory.CreateDirectory(localPath);
}
localPath += "/" + fileName;
if (File.Exists(localPath))
{
File.Delete(localPath);
}
FileStream fs = new FileStream(localPath, FileMode.CreateNew);
StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
sw.AutoFlush = true;
htmlCode = htmlCode.Replace("╬", "\"");
sw.Write(htmlCode);
sw.Flush();
sw.Close();
fs.Close();
}
string path = filename;
try
{
if (isunicode)
{
using (StreamWriter sw = new StreamWriter(path, isAppend, Encoding.Unicode))
{
sw.WriteLine(line);
}
}
else
{
using (StreamWriter sw = new StreamWriter(path, isAppend))
{
sw.WriteLine(line);
}
}
return true;
}