Why does read only file fail on ....

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
 
J

Josip Medved

    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.
 
J

Jack Jackson

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.
 

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

Top