Why does read only file fail on ....

  • Thread starter Thread starter Lloyd Sheen
  • Start date Start date
L

Lloyd Sheen

Code is:
Using stream As Stream = New FileStream(jpgs(0), FileMode.Open)
img = Image.FromStream(stream)
End Using


If the file is read only then it fails. If I change the attribute it is ok.
Since I am just reading the file it seems strange or is there other
parameters that I can use to get around this?

I am using this code so that the program does not hold a reference to the
file after I set a picturebox image to the variable img.

Thanks
LS
 
    Using stream As Stream = New FileStream(jpgs(0), FileMode.Open)
     img = Image.FromStream(stream)
    End Using
If the file is read only then it fails.  If I change the attribute it is ok.

Just add FileAccess.Read as third attribute.
 
Code is:
Using stream As Stream = New FileStream(jpgs(0), FileMode.Open)
img = Image.FromStream(stream)
End Using


If the file is read only then it fails. If I change the attribute it is ok.
Since I am just reading the file it seems strange or is there other
parameters that I can use to get around this?

I am using this code so that the program does not hold a reference to the
file after I set a picturebox image to the variable img.

Thanks
LS

According to the documentation for the FileStream constructor you show
above (<http://msdn.microsoft.com/en-us/library/47ek66wy.aspx>):

"The constructor is given read/write access to the file...".

I would think you would need to supply a FileAccess parameter to get
only Read access.
 
Back
Top