C# 如何捕获文件的关闭事件
我在做一个文件管理的功能,实现思路是,当文件打开时 数据库改为“已打开的状态”,关闭后状态修改为“未打开状态”。目前使用的打开的方式代码如下:
OpenFileDialog openFileDialog = new OpenFileDialog();
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
//打开文件
Process myProcess = new Process();
try
{
myProcess.StartInfo.FileName = openFileDialog.FileName;
myProcess.EnableRaisingEvents = true;
myProcess.Exited += new EventHandler(myProcess_Exited);
myProcess.Start();
}
catch (Exception ex)
{
}
}
关闭进程时这样的方式可以捕获。但myProcess.Exited 这个事件只是捕获进程关闭时触发,如果换成word这类文件不论开多少个都只有一个进程,必须要关闭到最后一个才能触发这个事件。请问有什么办法可以捕获当前文件关闭时的事件。
C# 捕获文件关闭事件 --------------------编程问答--------------------
System.IO.FileInfo fi = new System.IO.FileInfo("abc.txt");
if (fi.Attributes == System.IO>FileAttributes.ReadOnly)
{
//这样可以不?
}
补充:.NET技术 , C#