Tuesday, June 13, 2006

Appending data from different text files to single file !!

These dayz I m doing nothing, except reading the code and tryin to understand it.
My senior came to me and asked me to write a small application to read all the text files from the directory and append their data into a file. Its a very small and easy thing to do, but still I m posting it thinking that this small piece of code will help someone.

using System.IO;
private void Form1_Load(object sender, EventArgs e)
{
DirectoryInfo dir1 = new DirectoryInfo(@"C:\abc");

FileInfo[] txtfiles = dir1.GetFiles("*.txt");

FileInfo fxists = new FileInfo(@"c:\abc\c.txt");
if (fxists.Exists)
{
fxists.Delete();
}

foreach (FileInfo f in txtfiles)
{
StreamReader sr = File.OpenText(f.Name);
string read = null;
while ((read = sr.ReadLine()) != null)
{

FileInfo fi = new FileInfo(@"c:\abc\c.txt");
StreamWriter sw = fi.AppendText();

sw.Write(read.ToString());
sw.Close();

}

}

}

Monday, April 24, 2006

Lately, I have been given the task of stealin data from the job sites like Yahoo, CarrerBuilder and Monster and others like Bigwheels & StylineConcepts. I m really pissed off by doing this job since the last 1 month or so. As soon as I finish off with the parsing of 1 site. Another site comes for the parsing. I m waiting for a new project which doesnt involve html parsing.

This is the function which i used to extract the html content of a page into the string and used it further as i required.

public string Find_Source_Code(string myURL)
{
if(myURL.Trim().Length<=0) return "";

string return_result = "";
System.Net.WebClient Http = new System.Net.WebClient();
WebRequest objRequest = System.Net.HttpWebRequest.Create(myURL);

try
{
using(StreamReader sr = new StreamReader(objRequest.GetResponse().GetResponseStream()))
{
return_result = sr.ReadToEnd();
sr.Close();
}
}
catch
{
return_result = "";
}
return return_result;
}


private void ParsenCheck()
{
string line=Find_Source_Code(url);
string[] Description;
Boolean flag;
flag=false;

Description=line.Split('\n');

//Some more string commands to parse the data
}