2012-03-16 89 views
0

有一個.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); 
     } 

有沒有更好的方法?

回答

1

我不知道,什麼是問題,但不是的,如果你可以使用

File.AppendAllText(string path, string content) 

http://msdn.microsoft.com/en-us/library/ms143356.aspx

+0

我有一個文本框A,B和C哪有HTML表單我與A,B和C寫入到一個新的HTML文件的值的形式,而無需重寫整個代碼。 – alsu3 2012-03-16 20:59:51

+0

你需要回傳表單數據轉換爲「人類可讀的」字符串(HTML文件)? – sasjaq 2012-03-16 21:16:36

+0

是的,這正是我想要做的。 – alsu3 2012-03-16 21:19:52