By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,471 Members | 732 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,471 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
----------------------------------------------------------

Thanks,
Ron
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Ron" <an*******@discussions.microsoft.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2

P: n/a
Ron
Thanks. I will give that a try.

-----Original Message-----
"Ron" <an*******@discussions.microsoft.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

.

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.