【发布时间】:2012-03-17 04:45:55
【问题描述】:
有一个 .net 站点,我正在尝试在完成后将表单的 html 副本保存到服务器。问题是我如何让它将数据保存到 html 文档中,而不必再次编写整个内容。当我意识到这一点时,我走到了这一步。
string activeDir = @"c:\Code";
DateTime time = DateTime.Now;
string folformat = "MMdyy";
string filformat = "hmsMMdyy";
string fdate = time.ToString(folformat);
string newPath = System.IO.Path.Combine(activeDir, fdate);
System.IO.Directory.CreateDirectory(newPath);
string newFileName = time.ToString(filformat)+".html";
newPath = System.IO.Path.Combine(newPath, newFileName);
if (!System.IO.File.Exists(newPath))
{
TextWriter tw = new StreamWriter(newPath);
tw.WriteLine(700linesofhtml);
}
有没有更好的方法?
【问题讨论】: