Friday, 23 August 2013

Saving source code formatting to TXT file

Saving source code formatting to TXT file

I am trying to extract the source code from a webpage and save it to a
text file. However, I want to keep the formatting of the source code.
My code is below.
// 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);
}
}
I would like the text file to show the source code as it is formatted in
the Messagebox.
Messagebox screenshot:
Text file screenshot:
How would I go about getting the text document's formatting to be the same
as in the Messagebox?

No comments:

Post a Comment