Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to save a webpage to the hard drive Because I'm using ifilter and itextsharp to index pages based on their filepath and not url
Posted
Comments
StianSandberg 19-Jul-12 7:49am    
ok. What is your question?
Nokukhanya01 19-Jul-12 7:52am    
@ AlluvialDeposit how to save a web page on the hard drive
ZurdoDev 19-Jul-12 7:56am    
In the browser, click File, Save As. My guess is you need to provide more information so it is clear what you are trying to do because it is not clear.
bbirajdar 19-Jul-12 8:03am    
But those are already saved on your website folder in IIS..Why do you want to save it again ?
StianSandberg 19-Jul-12 8:05am    
I agree.. If it's your own website then you don't have to go the "download --> save as html --> convert html to pdf --> index" way.. Totally unnecessary.

1 solution

You can use a WebClient to fetch a webpage.

C#
string html;
var req = WebRequest.Create("http://www.codeproject.com") as HttpWebRequest;
var res = (HttpWebResponse)req.GetResponse();

using (var srResponseReader = new StreamReader(res.GetResponseStream()))
{
    html = srResponseReader.ReadToEnd();
    srResponseReader.Close();
}

res.Dispose();


After you fetch the website you just save the string (containing all the html):
C#
System.IO.File.WriteAllText("c\\file.txt", html);


But if you want to download all the images, scripts, css etc. it's a little more complex.
Convert any URL to a MHTML archive using native .NET code[^]
 
Share this answer
 
v4
Comments
Nokukhanya01 19-Jul-12 8:07am    
@AlluvialDepot i want to download all images ,sripts ang so on
StianSandberg 19-Jul-12 8:10am    
ok, then you should have a look at this article: http://www.codeproject.com/Articles/8268/Convert-any-URL-to-a-MHTML-archive-using-native-NE

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900