Hi,
I am working on winform applications
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
.....
}
am writing above code to Read DAT file but some times I am getting following exception
"The process cannot access the file 'C:\data\myfile.dat' because it is being used by another process."
Can you tel me how to solve this problem ?
Loading
Suthish NairPosted Nov 6, 2011, 10:12 AM
bool blnFileAlreayOpened = false;
try
{
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
blnFileAlreayOpened = true;
}
blnFileAlreayOpened = false;
}
catch (Exception)
{
blnFileAlreayOpened = true;
}
if (blnFileAlreayOpened == true)
{
// throw error
}
VulpesPosted Nov 4, 2011, 9:03 AM
1. You've opened the file elsewhere in your application but not closed it.
2. Another user, or application, has already opened the file for exclusive access?