我試圖從網頁中提取源代碼並將其保存到文本文件中。但是,我想保留源代碼的格式。將源代碼格式保存爲TXT文件
我的代碼如下。
// this block fetches the source code from the URL entered.
private void buttonFetch_Click(object sender, EventArgs e)
{
using (WebClient webClient = new WebClient())
{
string s = webClient.DownloadString("http://www.ebay.com");
Clipboard.SetText(s, TextDataFormat.Text);
string[] lines = { s };
System.IO.File.WriteAllLines(@"C:\Users\user\Dropbox\Personal Projects\WriteLines.txt", lines);
MessageBox.Show(s.ToString(), "Source code",
MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
}
}
我想讓文本文件顯示源代碼,因爲它是在消息箱中格式化的。
消息框截圖:
文本文件截圖:
我怎麼會去獲取文本文檔的格式是一樣的消息框?
用記事本++打開它,它應該工作。 由於一些奇怪的原因,記事本想要在它讀取新行的方式上有所不同http://notepad-plus-plus.org/如果這種方法可行並且對您而言可以,我會將其添加爲答案,否則我會只是把它保留在評論中 –