how to unset/reset ReadOnly mode of an Excel file?

R

Ron

Hello,

the following sub (below) reads an excel file to a webpage
using BinaryReader. If anyone tries to modify the excel
file from the browser this places the excel file in
ReadOnly mode, and no one can then touch the file, I can't
delete it, etc. The file will still display on the
browser. The only way I have been able to release the
file from ReadOnly mode is to reboot the server computer.
Obviously, I can't keep doing that. Does anyone know if
there is a way to reset/unset the ReadOnly mode of the
Excel file? or how to make it not go into ReadOnly mode?

------------------------------------------------------
Private Sub GetFile()
Dim FilePath As String = Cache("strFile").ToString
If Not Dir(FilePath).Equals("") Then
Dim fs As New FileStream(FilePath, FileMode.Open,
FileAccess.Read)
Dim bw As New System.IO.BinaryReader(fs)
Dim byt() As Byte, i As Integer
byt = bw.ReadBytes(CInt(fs.Length))
i = byt.Length()
Response.ContentType = "application/vnd.ms-excel"
Response.OutputStream.Write(byt, 0, i)
Response.OutputStream.Close()
response.write("testing")
End If
End Sub
 
H

Herfried K. Wagner [MVP]

Ron said:
the following sub (below) reads an excel file to a webpage
using BinaryReader. If anyone tries to modify the excel
file from the browser this places the excel file in
ReadOnly mode, and no one can then touch the file, I can't
delete it, etc. The file will still display on the
browser. The only way I have been able to release the
file from ReadOnly mode is to reboot the server computer.
Obviously, I can't keep doing that. Does anyone know if
there is a way to reset/unset the ReadOnly mode of the
Excel file? or how to make it not go into ReadOnly mode?

You can try to specify 'FileShare.ReadWrite' in the constructor of your
'FileStream'. Maybe this helps.
 

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