Uncategorized

download a binary stream in asp.net

Response.buffer = true;
Response.ContentType = “application/pdf”;
Response.AppendHeader(“Content-Disposition”,”attachment; filename=output.pdf”);
Response.BinaryWrite(convertedFile); //Converted file is a byte array
Response.End();

http://www.west-wind.com/weblog/posts/2007/May/21/Downloading-a-File-with-a-Save-As-Dialog-in-ASPNET

Advertisements

4 thoughts on “download a binary stream in asp.net

  1. You could just provide a hyperlink tag in the page to the file, like “Download here.” or “Download ” if you want to do it server-side. I don’t know why someone would go through the trouble of doing it the way you suggest. Maybe you could tell us when it would be more beneficial?

    1. The requirement is *not* to store pdf document in the file system. so I have to use this option to flush the pdf file as a binary stream to the user. “Download here” hyperlink also seems a good option.

  2. The tags didn’t go through, but I posted meant to post “Download <a href=’output.pdf’>here</a> and “Download <asp:HyperLink NavigationUrl=”output.pdf” Text=”here” runat=”server”></asp:HyperLink>.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s