Solved

Save web page programmatically in C# -  HttpWebRequest or better option.

Posted on 2010-08-13
3
1,747 Views
Last Modified: 2012-06-21
I'm trying to save a webpage to an htm file using C# and HttpWebRequest.

It does work, but it does not save all the data. (As oppose to opening the page in a browser and selecting and saving page complete)

How can I do this programmatically? I'm trying to avoid having to ShellExecute IE or Firefox and then sending it PostMessages to save the page.

Other info:
I'm on a WindowsXP system, and will take suggestions for either IE or Firefox.
HttpWebRequest WebRequestObject = (HttpWebRequest)HttpWebRequest.Create(url);
            WebResponse Response = WebRequestObject.GetResponse();
            Stream WebStream = Response.GetResponseStream();
            StreamReader Reader = new StreamReader(WebStream);
            string PageContent = Reader.ReadToEnd();

            // Cleanup
            Reader.Close();
            WebStream.Close();
            Response.Close();

			
            sr.WriteLine(PageContent);
            sr.Close();

Open in new window

0
Comment
Question by:silentthread2k
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
nmarun earned 250 total points
ID: 33434994
What is it that the response object not getting from the site? What specific segment is is missing?

See this recent thread on a very similar issue:

http://www.experts-exchange.com/Programming/Languages/.NET/Q_26394278.html?cid=1572#a33412826

Arun
0
 
LVL 11

Assisted Solution

by:PlatoConsultant
PlatoConsultant earned 250 total points
ID: 33435154
http://www.codeproject.com/KB/webservices/HttpWebRequest_Response.aspx

HttpWebRequest/Response in a Nutshell


 very simple to use code

0
 
LVL 11

Expert Comment

by:PlatoConsultant
ID: 33435157
But my suggestion is to use the browser control available in the toolbox.


http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspx

WebBrowser Class
Enables the user to navigate Web pages inside your form.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now