如何查找是否在记事本中打开特定的.txt文件?
我试过这里提到的解决方案
但它们适用于Word和pdf文件,但不适用于在记事本中打开的txt文件.
这是我写的代码.
public bool IsFileOpen(string strFileName)
{
bool retVal = false;
try
{
if (File.Exists(pstrFileName))
{
using (FileStream stream = File.OpenWrite(pstrFileName))
{
try
{
}
catch (IOException)
{
retVal = true;
}
finally
{
stream.Close();
stream.Dispose();
}
}
}
}
catch (IOException)
{ //file is opened at another location
retVal = true;
}
catch (UnauthorizedAccessException)
{ //Bypass this exception since this is due to the file is being set to read-only
}
return retVal;
}
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么.
我的要求: …