views:

415

answers:

1

I have a webbrowser control that displays some xml, when I access the document propertie I get the HTML that the control generated and not the xml. How do I save the "source" of the document? (can't use the webclient)

A: 

you have the original path don't you?

string urlPath = wb.Url;

why not download the source from there?

private string GetSourceCode(string sourceUrl) {
   String url = String.Format(sourceUrl);

   WebClient client = new WebClient();
   client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0;)"); // pass as Internet Explorer 7.0

   Stream data = client.OpenRead(url);
   StreamReader reader = new StreamReader(data);
   s = reader.ReadToEnd();
   data.Close();
   reader.Close();

   return s;
}

using the GetSourceCode() Method you have the entire source (the original one) in the returned string... do what you want with it ;)

string xmlSource = GetSourceCode(wb.Url);
balexandre