Click here to Skip to main content
15,902,636 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my webaplicaton is redirecting to google search engine ..i want to save pages from google search engine to my directory..how will i do it automatically...
Posted
Comments
Joezer BH 5-May-13 10:11am    
What seems to be the problem?
[no name] 5-May-13 10:14am    
how to save webpages from google to my directory or folder inside asp.net automatically rather doing manually
[no name] 5-May-13 10:44am    
im getting error on line source=sr.readtoend();
Joezer BH 6-May-13 2:51am    
try this:

WebClient client = new WebClient();
string downloadString = client.DownloadString("http://www.gooogle.com");


1 solution

You can use the following code to get the content of a web page into a string:

C#
string url = "some site";
string source = string.Empty;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using(StreamReader sr = new StreamReader(response.GetResponseStream()){
    source = sr.ReadToEnd();
}
* You will the the content placed in the string source

Optional snippet:
F#
WebClient client = new WebClient();
string downloadString = client.DownloadString("http://www.gooogle.com");



Cheers,
Edo
 
Share this answer
 
v2
Comments
[no name] 5-May-13 10:49am    
protected void button5_OnClick(object sender, EventArgs e)
{

string url = "http://www.google.com";
string source = string.Empty;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using(StreamReader sr = new StreamReader(response.GetResponseStream()))
{
source = sr.ReadToEnd();

}

}




code error please help
Joezer BH 5-May-13 10:51am    
What's the error?
[no name] 5-May-13 10:57am    
when clicking the button nothing is happening...please help...
i want to do like this..when the button is clicked it has to go to google website and wen i save webpages it has to be get saved to a folder inside asp.net c# automatically!!!!
Joezer BH 5-May-13 11:01am    
You have to implement each of the steps along the way.
With the code above you can read the content of the website, the next step would be to store it into any form you like, you can save it as an HTML page on a local or remote directory if you like, or store it into a DB etc.
Joezer BH 5-May-13 11:03am    
I suggest you divide your question into several steps and ask questions for each one that you need help with.

e.g.:

1. How to browse to a website using C#?
2. How to get the content of a webpage using C# into a string?
3. How to save a string to a newly created file?
...
...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900