写变量为一个html文件
问题描述:
有一个.NET网站,我想获得形式的副本保存到服务器上的HTML当他们完成。问题是如何得到它来保存数据到一个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);
}
有没有更好的方法?
答
我不知道,什么是问题,但不是的,如果你可以使用
File.AppendAllText(string path, string content)
我有一个文本框A,B和C哪有HTML表单我与A,B和C写入到一个新的HTML文件的值的形式,而无需重写整个代码。 – alsu3 2012-03-16 20:59:51
你需要回传表单数据转换为“人类可读的”字符串(HTML文件)? – sasjaq 2012-03-16 21:16:36
是的,这正是我想要做的。 – alsu3 2012-03-16 21:19:52