session101 Posted May 16, 2006 Posted May 16, 2006 I have a web app that opens the appropriate application based on the file extension using Response.ContentType. When I open an xls file, I would like the file to be opened in read-only permissions with Excel. How would I do this? Here is my existing code: switch (file.Extension) { case ".pdf": Response.ContentType = "application/pdf"; break; case ".htm": case ".html": Response.ContentType = "text/html"; break; case ".txt": Response.ContentType = "text/plain"; break; case ".doc": Response.ContentType = "application/msword"; break; case ".xls": case ".csv": Response.ContentType = "application/xls"; break; default: Response.ContentType = "application/unknown"; break; } Response.Flush(); Response.WriteFile(file.FullName); Response.End(); TIA. Quote
Arch4ngel Posted May 16, 2006 Posted May 16, 2006 You could open a Filestream with the proper access right and copy this stream to Response.OutputStream. Never tried but don't forget to close the stream after. I would see something like that: -Open stream -Copy stream to OutputStream -Flush the response -Close stream Anyone can confirm that please? I have a web app that opens the appropriate application based on the file extension using Response.ContentType. When I open an xls file, I would like the file to be opened in read-only permissions with Excel. How would I do this? Here is my existing code: switch (file.Extension) { case ".pdf": Response.ContentType = "application/pdf"; break; case ".htm": case ".html": Response.ContentType = "text/html"; break; case ".txt": Response.ContentType = "text/plain"; break; case ".doc": Response.ContentType = "application/msword"; break; case ".xls": case ".csv": Response.ContentType = "application/xls"; break; default: Response.ContentType = "application/unknown"; break; } Response.Flush(); Response.WriteFile(file.FullName); Response.End(); TIA. Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
mem98 Posted December 31, 2008 Posted December 31, 2008 Use a Response.Redirect() to the URL of your file. This will open the file, but if you want it Read-Only specify that in the security properties of your file. (Right Click, Properties, Security, and Revoke Write permissions for users and Grant for Admin) It seemed not to work at first but if you access it as a user through the Response.Redirect(filePath) and edit it, when you try to save your change Windows will prevent it. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.