mscorlib: Access to the path is denied.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm tring to open a file using FileStream:
dim myFile As New FileStream(myPath, FileMode.Open)

It works on every file on FAT32 HDD fine.
But when I try to open a several files on NTFS drive I get this message:
'Access to the path " ... " is denied.'

Some files on NTFS are working fine.
I checked the permitions and I do have the permition to do everything with
this file or folder as I'm the administrator of this PC.

What am I doing wrong?
 
If you are opening it for reading only, you should use the overloaded
constructor that receives a System.IO.FileShare param and pass it
System.IO.FileShare.Read, because by default is open for write and if 2
processes do the same, one of them denies access to the other:

public FileStream ( System.String path , System.IO.FileMode mode ,
System.IO.FileAccess access , System.IO.FileShare share )
 
Thanks it helped !



Carlos J. Quintero said:
If you are opening it for reading only, you should use the overloaded
constructor that receives a System.IO.FileShare param and pass it
System.IO.FileShare.Read, because by default is open for write and if 2
processes do the same, one of them denies access to the other:

public FileStream ( System.String path , System.IO.FileMode mode ,
System.IO.FileAccess access , System.IO.FileShare share )


--

Carlos J. Quintero

The MZ-Tools all-in-one add-in, now for .NET: http://www.mztools.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top