2

I have an attachment whose data(of type varbinary) and MIME type come from the DB. When the user clicks on a link, I get the data and write it to HttpContext.Response.BinaryWrite. Currently, I have the user force download the attachment with

r.AddHeader("Content-Disposition", "attachment; filename=" + a.FileName);

Instead, I'd like for the file to open, I tried

r.AddHeader("Content-Disposition", "inline; filename=" + a.FileName);

However, this just opens the image files, all other types of attachments get downloaded automatically. How do i get these files to display as well? If these cannot be displayed, I'd like Windows to handle it by displaying the "Open With" dialog.

In this question that I've posted, someone said that I can render an html view of the file, I'm not sure how that can be done. I'm using the .NET environment with C#.

Any thoughts on this would really help.

Community
  • 1
  • 1
neuDev33
  • 1,573
  • 7
  • 41
  • 54
  • what kind of file other than images do you want to transfer to the client? – shriek May 07 '12 at 16:59
  • Is this a WinForms application or an ASP.NET application? – Icemanind May 07 '12 at 17:01
  • 3
    I think what you're asking for is determined by the client's browser settings; your web app cannot decide whether this binary stream is to be downloaded or prompt the user with "open with"... not to mention the different browsers out there. – BeemerGuy May 07 '12 at 17:02
  • @shriek They could be any kind of file the user has previously attached himself - .txt, .doc, .xls, .pdf, etc – neuDev33 May 07 '12 at 17:07
  • @icemanind It is an ASP.NET application – neuDev33 May 07 '12 at 17:07
  • @BeemerGuy.net In that case, let's say I'd be okay with having say a .pdf file getting force downloaded, but can the browser atleast open .doc and .xls files? Or is this not possible? Any idea about rendering an html view of the file? – neuDev33 May 07 '12 at 17:09
  • 2
    @neuDev33 -- if you think about it, "opening" and "downloading" are objectively the same thing. But, you can send out the correct MIME type, and cross your fingers that the browser will act like you'd expect... check this question and its answer http://stackoverflow.com/questions/2519026/how-do-you-stream-an-excel-2007-or-word-2007-file-using-asp-net-and-c-sharp – BeemerGuy May 07 '12 at 17:56

1 Answers1

0

You could try

r.ContentType = "application/force-download"
DRobertE
  • 3,478
  • 3
  • 26
  • 43