用 FileSystemWatcher监视文件夹, e.FullPath返回文件发生变化的路径加文件名,再用e.FullPath.Substring(e.FullPath.Length -10,10).Substring(e.FullPath.Length -10,10)分离出文件名,用if语句判断文件名是否相等。
if (e.FullPath.Substring(e.FullPath.Length -10,10) ==textBox16.Text)
{
MessageBox.Show(e.FullPath);
}在窗体textBox16的text中是“999999.TXT”,上面的if语句在执行时立即程序窗体消失,visual studio 连错都不报,程序就不在了。
但下面语句是可以正确执行的,将textBox16.Text直接写成“999999.TXT” if (e.FullPath.Substring(e.FullPath.Length -10,10) ==“999999.TXT”)
{
MessageBox.Show(e.FullPath);
}
请问如何做变正确用==textBox16.Text
if (e.FullPath.Substring(e.FullPath.Length -10,10) ==textBox16.Text)
{
MessageBox.Show(e.FullPath);
}在窗体textBox16的text中是“999999.TXT”,上面的if语句在执行时立即程序窗体消失,visual studio 连错都不报,程序就不在了。
但下面语句是可以正确执行的,将textBox16.Text直接写成“999999.TXT” if (e.FullPath.Substring(e.FullPath.Length -10,10) ==“999999.TXT”)
{
MessageBox.Show(e.FullPath);
}
请问如何做变正确用==textBox16.Text
解决方案 »
- 100求解:winform backgroundworker内调用控件,出现线程间操作无效
- 请问,如何在程序所在目录下的某个文件夹下新建一个文件夹
- 数据结构怎么学
- C# 插入数据问题
- 关于系统架构问题
- ASPnetPagerV2netfx2_0的问题
- Enterprise Library 在中型mis系统是否使用了,谢谢了
- 《Pro C# 2005 and the .NET 2.0 Platform》与《Practical .Net2 and C#2》的翻译
- 能否程序控制IIS回收(我知道可以自动回收,但需要用程序控制)。
- 如何用javascript调用c#编译的类库dll
- COOKIES的保存和获取
- C#winform程序中添加对表结构修改的界面
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = "E:\aaa";
watcher.Changed += new FileSystemEventHandler(watcher_Changed);
watcher.EnableRaisingEvents = true;
private void watcher_Changed(object sender, FileSystemEventArgs e)
{
//要将e.FullPath分开,直接与bbb.txt比较 if (e.FullPath.Substring(e.FullPath.Length -10,10) =="999999.TXT")
{
MessageBox.Show(e.FullPath);
}
else
{
MessageBox.Show("555");
}
}
private System.IO.FileSystemWatcher fileSystemWatcher1
窗体设计器生成的代码
this.fileSystemWatcher1 = new System.IO.FileSystemWatcher();
((System.ComponentModel.ISupportInitialize)(this.fileSystemWatcher1)).BeginInit();
//
this.fileSystemWatcher1.EnableRaisingEvents = true;
this.fileSystemWatcher1.SynchronizingObject = this;
this.fileSystemWatcher1.Changed += new System.IO.FileSystemEventHandler(this.fileSystemWatcher1_Changed);
可能fileSystemWatcher并不能在wpf下用。