I Want to download the source code of a webpage using webbrowser control. I am new to this can u help me in downloading and loading the source code using c#.
or is there any other way to download????
I used httprequest and httpresponse ,streamreader to do this ,but i get the error
The remote server returned an error: (400) Bad Request.
Mohsinkhan, for me, it is unclear what you wish to do ... please clarify.
(a) is it for ANY webpage that you wish to download "source code"?
(b) by "source code", do you mean the HTML that one sees when one views source in a browser?
or, do you mean the c# source code that was used to generate the HTML?
It would be easier for your peers here at forums.asp.net to help you if you shared your
relevant code snippets.
g.
P.S.: if you mean the code used to generate the HTML, then you can not
get such code through a standard request; to access such code, you would require appropriate permissions from the website's owner on the server and would need to use a technology such as remote desktop, vpn, FTP, ...
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
for more, Google use c# .net to download entire web page
g,
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
Mohsinkhan
0 Points
6 Posts
how to download source code of webpage using webbrowser control or any other ways.
Aug 01, 2012 07:08 AM|LINK
I Want to download the source code of a webpage using webbrowser control. I am new to this can u help me in downloading and loading the source code using c#.
or is there any other way to download????
I used httprequest and httpresponse ,streamreader to do this ,but i get the error
The remote server returned an error: (400) Bad Request.
how can i download the source code. PLease help.
Thanks in advance.
AidyF
Star
9204 Points
1570 Posts
Re: how to download source code of webpage using webbrowser control or any other ways.
Aug 01, 2012 10:06 AM|LINK
Use the WebClient class
http://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.100).aspx
Or HttpWebRequest
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx
Mudasir.Khan
All-Star
15346 Points
3142 Posts
Re: how to download source code of webpage using webbrowser control or any other ways.
Aug 01, 2012 10:18 AM|LINK
please check this
http://www.dotnetperls.com/webclient
gerrylowry
All-Star
20513 Points
5712 Posts
Re: how to download source code of webpage using webbrowser control or any other ways.
Aug 01, 2012 09:27 PM|LINK
@ Mohsinkhan
welcome to forums.asp.net
Mohsinkhan, for me, it is unclear what you wish to do ... please clarify.
(a) is it for ANY webpage that you wish to download "source code"?
(b) by "source code", do you mean the HTML that one sees when one views source in a browser?
or, do you mean the c# source code that was used to generate the HTML?
It would be easier for your peers here at forums.asp.net to help you if you shared your relevant code snippets.
g.
P.S.: if you mean the code used to generate the HTML, then you can not get such code through a standard request; to access such code, you would require appropriate permissions from the website's owner on the server and would need to use a technology such as remote desktop, vpn, FTP, ...
Paul Linton
Star
13421 Points
2535 Posts
Re: how to download source code of webpage using webbrowser control or any other ways.
Aug 01, 2012 09:52 PM|LINK
Show us the code that returns the error. It is very hard to debug code if you cannot see it.
Mohsinkhan
0 Points
6 Posts
Re: how to download source code of webpage using webbrowser control or any other ways.
Aug 03, 2012 04:50 AM|LINK
public void acc()
{
WebClient client = new WebClient();
string reply = client.DownloadString("http://www.google.com/");
HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
htmlDocument.LoadHtml(reply );
// string articleTitle = htmlDocument.DocumentNode.SelectNodes("/div");
Response.Write(reply);
}
Mohsinkhan
0 Points
6 Posts
Re: how to download source code of webpage using webbrowser control or any other ways.
Aug 03, 2012 04:51 AM|LINK
Hi, Iwant to download the html source code that we can see when we right click and click view source.
gerrylowry
All-Star
20513 Points
5712 Posts
Re: how to download source code of webpage using webbrowser control or any other ways.
Aug 03, 2012 05:49 AM|LINK
@ Mohsinkhan
check out these links:
http://msdn.microsoft.com/en-us/library/system.net.webclient.aspx
http://www.dotnetperls.com/webclient
http://stackoverflow.com/questions/1430918/c-sharp-code-for-saving-an-entire-web-page-with-images-formatting
"C# code for saving an entire web page? (with images/formatting)"
http://stackoverflow.com/questions/26233/fastest-c-sharp-code-to-download-a-web-page
"Fastest C# Code to Download a Web Page"
et cetera
for more, Google use c# .net to download entire web page
g,
gerrylowry
All-Star
20513 Points
5712 Posts
Re: how to download source code of webpage using webbrowser control or any other ways.
Aug 03, 2012 05:57 AM|LINK
@ Mohsinkhan
here's an example from the http://www.dotnetperls.com/webclient link:
// Create web client. System.Net.WebClient client = new System.Net.WebClient(); // Download string. string value = client.DownloadString("http://www.dotnetperls.com/"); // Write values. Console.WriteLine("--- WebClient result ---"); Console.WriteLine(value.Length); Console.WriteLine(value);output:
g.