1
我正在開發觀察文件更改,顯示通知並將更改列表插入listview.I很難只想更改通知如果更改excel文件的屬性。現在如果更改excel屬性,顯示創建,刪除,重命名通知。 任何人都可以向我建議嗎?如何看C#中的excel文件更改?
代碼:
string filepath = C:\New Folder;
private void watcher_Changed(object sender, FileSystemEventArgs e)
{
sfilepath = e.FullPath.Substring(0, e.FullPath.Length - e.Name.Length - 1);
if (sfilepath == filepath)
{
FileInfo fileInfo = new FileInfo(e.FullPath);
DateTime lastWriteTime = fileInfo.LastWriteTime;
DateTime nowdt = DateTime.Now;
if (lastWriteTime == nowdt)
{
this.notifyIcon1.ShowBalloonTip(1, "File " + e.ChangeType, e.FullPath, ToolTipIcon.Info);
}
}
}
private void watcher_Created(object sender, FileSystemEventArgs e)
{
sfilepath = e.FullPath.Substring(0, e.FullPath.Length - e.Name.Length - 1);
if (sfilepath == filepath)
{
this.notifyIcon1.ShowBalloonTip(1, "File " + e.ChangeType, e.FullPath, ToolTipIcon.Info);
}
}
private void watcher_Deleted(object sender, FileSystemEventArgs e)
{
sfilepath = e.FullPath.Substring(0, e.FullPath.Length - e.Name.Length - 1);
if (sfilepath == filepath)
{
this.notifyIcon1.ShowBalloonTip(1, "File " + e.ChangeType, e.FullPath, ToolTipIcon.Info);
}
}
private void watcher_Renamed(object sender, RenamedEventArgs e)
{
sfilepath = e.FullPath.Substring(0, e.FullPath.Length - e.Name.Length - 1);
if (sfilepath == filepath)
{
this.notifyIcon1.ShowBalloonTip(1, "File Renamed", e.OldFullPath + " renamed to " + e.FullPath, ToolTipIcon.Info);
}
}
更改列表:
New Microsoft Excel ワークシート.xls 2011/10/10 11:00:15 Created C:\New Folder
B1F38000 2011/10/10 11:00:55 Created C:\New Folder
New Microsoft Excel ワークシート.xls~RF83f213.TMP 2011/10/10 11:01:16 Created C:\New Folder
New Microsoft Excel ワークシート.xls 2011/10/10 11:01:16 Deleted C:\New Folder
New Microsoft Excel ワークシート.xls 2011/10/10 11:01:16 Renamed C:\New Folder
New Microsoft Excel ワークシート.xls~RF83f213.TMP 2011/10/10 11:01:18 Deleted C:\New Folder
您可以檢查FileSystemEventArgs的ChangeType –