Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-08-13
3
Medium Priority
?
1,895 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
nmarun earned 1000 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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Simple Linear Regression

721 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