Search the web
Sign In
New User? Sign Up
codesnips · Code Snippets
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want to share photos of your group with the world? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
[C#] Retrieve WebPage programmatically and Save in File   Message List  
Reply | Forward Message #28 of 48 |

// imports

using System;

using System.Net;

using System.IO;

using System.Text;

// capture webpage by using HttpWebRequest class and Save into file. File is saved in a separate directory for each day. Please check out the method to create directory daywise.

// create an object of HttpWebRequest

string link = www.microsoft.com;

Uri pageUri = new Uri(link);

HttpWebRequest pageRequest = (HttpWebRequest)WebRequest.Create(pageUri);

try

{

WebResponse pageRes = pageRequest.GetResponse();

StreamReader sr = new StreamReader(pageRes.GetResponseStream());

String pageText = sr.ReadToEnd();

SaveToFile( pageText );

}

catch(WebException we)

{

}

 

-----------------------------------------------------------------------------------------------------------

// SaveToFile function

-----------------------------------------------------------------------------------------------------------   

private void SaveToFile( string pageText )

{

// check whether the directory is present

string currDir = Directory.GetCurrentDirectory();

// getting current date

DateTime dt = DateTime.Now;

string todayDir = currDir + @"\" + dt.ToString("ddMMyyyy");

string indexPath = todayDir + @"\index.xml";

// check whether its there

if (!Directory.Exists(todayDir))

{

// create directory

Directory.CreateDirectory(todayDir);

// Write pageText to file

string pathName = todayDir + @"\WebPage.html";

StreamWriter writeFile = File.CreateText(pathName);

writeFile.Write(pageText);

writeFile.Close();

}

catch(Exception e)

{

}

 

} // End of SaveToFile function

 
// WARNING: Compiled by Outlook


Fri Feb 28, 2003 5:22 pm

laghari78
Online Now Online Now
Send Email Send Email

Forward
Message #28 of 48 |
Expand Messages Author Sort by Date

// imports using System; using System.Net; using System.IO; using System.Text; // capture webpage by using HttpWebRequest class and Save into file. File is...
Nauman Leghari
laghari78
Online Now Send Email
Feb 28, 2003
5:25 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help