Solved

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

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Part One of the two-part Q&A series with MalwareTech.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Simple Linear Regression

631 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