Save any web page

We can save the web page using following simple code

using System.Net;
using System.IO;

public class SaveWebPage {
public static void Main() {
String MyPage = "";
HttpWebRequest MyHttpWebRequest = (HttpWebRequest)WebRequest.Create(MyPage);
HttpWebResponse MyHttpWebResponse =(HttpWebResponse) MyHttpWebRequest.GetResponse();
Stream MyDataStream = MyHttpWebResponse.GetResponseStream();
StreamReader MyStreamReader = new StreamReader(MyDataStream);
String MyDataString = MyStreamReader.ReadToEnd();

Code Explanation

1. Create the instance of HttpWebRequest using your web page.
2. Create the instance of HttpWebResponse by geting response
3. Read the response using stramreader and use it.
4. convert it into string.
5. If you need save the stream into a file



No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: