Sending a file to Response

Discussion in 'ASP .Net' started by Nathan Sokalski, Sep 19, 2007.

  1. I have an application in which I want to allow users to view certain files
    that are on the server, but not part of the application. To do this, I
    figured I would have ASP.NET read the files and send them to Response. I
    have done this with images by reading them into a Bitmap object and then
    using the following code:

    Response.ClearContent()
    Response.ContentType = "image/gif"
    mybitmap.Save(Response.OutputStream, ImageFormat.Gif)

    I will obviously need to use the Response.ClearContent() and
    Response.ContentType lines, but because the files are not necessarily
    images, I need to know how to send them to Response. I would have though
    that

    Response.WriteFile(filepath)
    OR
    Response.TransmitFile(filepath)

    would work, but apparently they didn't. The basic idea is just reading and
    writing a file, except the "writing" is more of a sending than a writing. I
    know how to allow people to download a file (using the "content-disposition"
    header), but what I want to do here is basically use a file in my site, but
    not put the file in my site directory. Any ideas? Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, Sep 19, 2007
    #1
    1. Advertising

  2. Greetings,

    As far as I know, Response.WriteFile() SHOULD work...

    Can you be more specific on what kind of error are you getting?

    PJ
    http://pjondevelopment.50webs.com

    On Sep 19, 6:24 pm, "Nathan Sokalski" <> wrote:
    > I have an application in which I want to allow users to view certain files
    > that are on the server, but not part of the application. To do this, I
    > figured I would have ASP.NET read the files and send them to Response. I
    > have done this with images by reading them into a Bitmap object and then
    > using the following code:
    >
    > Response.ClearContent()
    > Response.ContentType = "image/gif"
    > mybitmap.Save(Response.OutputStream, ImageFormat.Gif)
    >
    > I will obviously need to use the Response.ClearContent() and
    > Response.ContentType lines, but because the files are not necessarily
    > images, I need to know how to send them to Response. I would have though
    > that
    >
    > Response.WriteFile(filepath)
    > OR
    > Response.TransmitFile(filepath)
    >
    > would work, but apparently they didn't. The basic idea is just reading and
    > writing a file, except the "writing" is more of a sending than a writing. I
    > know how to allow people to download a file (using the "content-disposition"
    > header), but what I want to do here is basically use a file in my site, but
    > not put the file in my site directory. Any ideas? Thanks.
    > --
    > Nathan Sokalski
    > ://www.nathansokalski.com/
     
    PJ on Development, Sep 20, 2007
    #2
    1. Advertising

  3. Are you doing WriteFile() without setting ContentType? ContentType is
    still required, WriteFile doesn't do it for you.

    If you are setting ContentType, then what exactly is happening? Are
    you getting an error? Are you getting an unexpected response? If so,
    what exactly? Use an HTTP monitor like Fiddler to see what's actually
    being sent; does it look correct?

    Sam

    ------------------------------------------------------------
    We're hiring! B-Line Medical is seeking .NET
    Developers for exciting positions in medical product
    development in MD/DC. Work with a variety of technologies
    in a relaxed team environment. See ads on Dice.com.


    On Wed, 19 Sep 2007 17:24:05 -0400, "Nathan Sokalski"
    <> wrote:

    >I have an application in which I want to allow users to view certain files
    >that are on the server, but not part of the application. To do this, I
    >figured I would have ASP.NET read the files and send them to Response. I
    >have done this with images by reading them into a Bitmap object and then
    >using the following code:
    >
    >Response.ClearContent()
    >Response.ContentType = "image/gif"
    >mybitmap.Save(Response.OutputStream, ImageFormat.Gif)
    >
    >I will obviously need to use the Response.ClearContent() and
    >Response.ContentType lines, but because the files are not necessarily
    >images, I need to know how to send them to Response. I would have though
    >that
    >
    >Response.WriteFile(filepath)
    >OR
    >Response.TransmitFile(filepath)
    >
    >would work, but apparently they didn't. The basic idea is just reading and
    >writing a file, except the "writing" is more of a sending than a writing. I
    >know how to allow people to download a file (using the "content-disposition"
    >header), but what I want to do here is basically use a file in my site, but
    >not put the file in my site directory. Any ideas? Thanks.
     
    Samuel R. Neff, Sep 20, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lars Netzel
    Replies:
    3
    Views:
    5,170
    Prakash
    Nov 7, 2005
  2. Replies:
    0
    Views:
    1,410
  3. Luke
    Replies:
    2
    Views:
    4,755
    Nigel Wade
    Mar 15, 2007
  4. Zam
    Replies:
    2
    Views:
    389
  5. .nLL
    Replies:
    1
    Views:
    161
    Anthony Jones
    Feb 13, 2007
Loading...

Share This Page