Solved

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

Posted on 2010-08-13
3
1,785 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

828 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