.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum


Posted By: Asha.MP     Posted Date: September 21, 2010    Points:2   Category :ASP.Net
How to use this for text files?

Author: Deco             
Posted Date: September 21, 2010     Points: 5   

using System;
using System.IO;

public class FileWatcher
public FileWatcher()
string fpath = @"D:\MyFolder";
//you can specify a file type or a specific filename as
//the second parameter of FileSystemWatcher or *.* for all
//type of files
FileSystemWatcher WatchFile = new FileSystemWatcher(fpath, "*.txt");
WatchFile.Created += new FileSystemEventHandler(this.FileCreated);
WatchFile.Renamed += new RenamedEventHandler(this.FileReNamed);
WatchFile.Deleted += new FileSystemEventHandler(this.FileDeleted);
WatchFile.EnableRaisingEvents = true;

public void FileCreated(object sender, FileSystemEventArgs e)
Console.WriteLine(e.Name); //or anything you wish to display
//do the processing of file and print it to
//pdf writer port.or to a printer
public void FileReNamed(object sender, RenamedEventArgs e)
Console.WriteLine("\nFile Renamed:\n");

Console.WriteLine("Change Type: {0}", e.ChangeType );
Console.WriteLine("Full Path: {0}", e.FullPath );
Console.WriteLine("Name: {0}", e.Name );
Console.WriteLine("Old Full Path: {0}", e.OldFullPath);
Console.WriteLine("Old Name: {0}", e.OldName );

public void FileDeleted(object sender,FileSystemEventArgs e)
static void Main(string[] args)
FileWatcher fw = new FileWatcher();
//sits idle and watches for any creation,renaming
//or deletion of file best use of this program is
//to run it as a windows service.


Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend