M
ms_bi_pete
Guest
Hi everybody,
I have written a program to check if it is possible to open a file in C#.
If my file is opened in another program (a text editor for instance), it should not be possible and return false, it returns true otherwise.
It works on my computer but not on my client server.
protected virtual bool IsFileLocked(FileInfo file)
{
try
{
using(FileStream stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None))
{
stream.Close();
}
}
catch (IOException)
{
//the file is unavailable because it is:
//still being written to
//or being processed by another thread
//or does not exist (has already been processed)
return true;
}
//file is not locked
return false;
}
Thanks for your help
Pete
Continue reading...
I have written a program to check if it is possible to open a file in C#.
If my file is opened in another program (a text editor for instance), it should not be possible and return false, it returns true otherwise.
It works on my computer but not on my client server.
protected virtual bool IsFileLocked(FileInfo file)
{
try
{
using(FileStream stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None))
{
stream.Close();
}
}
catch (IOException)
{
//the file is unavailable because it is:
//still being written to
//or being processed by another thread
//or does not exist (has already been processed)
return true;
}
//file is not locked
return false;
}
Thanks for your help
Pete
Continue reading...