How to binary stream a file to user

Posted on 2006-05-21
Last Modified: 2010-04-16

I want to binary stream a file i.e. 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?

Question by:infodigger
    1 Comment
    LVL 20

    Accepted Solution

    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);

    The ContentType is different for every file type and you can find it in google.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now