Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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.

"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

  • 2 years later...
Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...