日期:2014-05-18 浏览次数:20979 次
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"D:\";
watcher.NotifyFilter = NotifyFilters.FileName;
watcher.Filter = "*.xls";
watcher.Changed += new FileSystemEventHandler(OnCreate);
watcher.Created += new FileSystemEventHandler(OnCreate);
//watcher.Deleted += new FileSystemEventHandler(OnDelete);
watcher.EnableRaisingEvents = true;
}
private static void OnCreate(object source, FileSystemEventArgs e)
{
if (File.Exists(e.FullPath) && e.Name.Substring(0, 1) != "~")
{
System.Diagnostics.Process.Start(e.FullPath);
//MessageBox.Show(e.Name.Substring(0,1));
}
}
}
}