How to binary stream a file to user

Hello,

I want to binary stream a file i.e. temp.zip to a visitor when he clicks on a link so that "save file as..." appears and allows him to save the file. I need the stream because the file will be located outside the wwwroot. Would it be possible to send me a sample code for this?

Thanks!
infodiggerAsked:
Who is Participating?
 
TheAvengerCommented:
You can create a page, set its content type to the appropriate file type, write the file in the reponse stream and finally end the response. An example would be:

this.Response.ContentType = contentType;
this.Response.OutputStream.Write(file, 0, file.Length);
this.Response.End();

The ContentType is different for every file type and you can find it in google.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.