Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
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 …
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…

747 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

16 Experts available now in Live!

Get 1:1 Help Now