Response.WriteFile question

Discussion in 'ASP .Net' started by enzeez, Apr 3, 2008.

  1. enzeez

    enzeez Guest

    Hello,

    I have a record stored in sqlserver database in binary form.
    I want to display a link that will allow user to download this record as
    a File.

    I want to create a file at runtime or pass a specified number of bytes
    to user's browser. I provide a link to the user and when he clicks the
    link i want a file dialog to appear and the user can then give a file
    name to store those bytes as a file.

    The problem is i need to create links dynamically and supply the binary
    or image bytes as a file download to user. How can i do this?

    Can someone help me out here?

    Thanks in advance
    enzeez
     
    enzeez, Apr 3, 2008
    #1
    1. Advertising

  2. I am sure your table will have a primary key and you will be using the
    primary key to fetch the content

    1) Link to some page like download.aspx and pass the key value (e.g. <a
    href="download.aspx?fileid=1234">download</a>)
    2) In download.aspx codebehind, write code to retrieve the content for this
    Id
    3) Write the resultset to using Response.binarywrite

    below is a asp code snippet which almost does the same.

    response.clear
    response.contentType = "application/octet-stream"
    response.addheader "content-disposition", "attachment; filename=" & FileName
    set stream = server.CreateObject("ADODB.Stream")
    stream.type = adTypeBinary
    stream.open
    stream.LoadFromFile Server.MapPath("/files") & FileName
    while not stream.EOS
    response.BinaryWrite Stream.Read(1024 * 64)
    wend
    stream.Close
    Set stream = Nothing
    response.Flush
    response.End


    Regards,
    Augustin Prasanna

    "enzeez" <> wrote in message
    news:u$...
    > Hello,
    >
    > I have a record stored in sqlserver database in binary form.
    > I want to display a link that will allow user to download this record as a
    > File.
    >
    > I want to create a file at runtime or pass a specified number of bytes to
    > user's browser. I provide a link to the user and when he clicks the link i
    > want a file dialog to appear and the user can then give a file name to
    > store those bytes as a file.
    >
    > The problem is i need to create links dynamically and supply the binary or
    > image bytes as a file download to user. How can i do this?
    >
    > Can someone help me out here?
    >
    > Thanks in advance
    > enzeez
     
    Augustin Prasanna, Apr 3, 2008
    #2
    1. Advertising

  3. enzeez

    enzeez Guest

    Augustin Prasanna wrote:
    Augustin Prasanna wrote:
    > I am sure your table will have a primary key and you will be using the
    > primary key to fetch the content
    >
    > 1) Link to some page like download.aspx and pass the key value (e.g. <a
    > href="download.aspx?fileid=1234">download</a>)
    > 2) In download.aspx codebehind, write code to retrieve the content for this
    > Id
    > 3) Write the resultset to using Response.binarywrite
    >
    > below is a asp code snippet which almost does the same.
    >
    > response.clear
    > response.contentType = "application/octet-stream"
    > response.addheader "content-disposition", "attachment; filename=" & FileName
    > set stream = server.CreateObject("ADODB.Stream")
    > stream.type = adTypeBinary
    > stream.open
    > stream.LoadFromFile Server.MapPath("/files") & FileName
    > while not stream.EOS
    > response.BinaryWrite Stream.Read(1024 * 64)
    > wend
    > stream.Close
    > Set stream = Nothing
    > response.Flush
    > response.End
    >
    >
    > Regards,
    > Augustin Prasanna
    >
    > "enzeez" <> wrote in message
    > news:u$...
    >> Hello,
    >>
    >> I have a record stored in sqlserver database in binary form.
    >> I want to display a link that will allow user to download this record as a
    >> File.
    >>
    >> I want to create a file at runtime or pass a specified number of bytes to
    >> user's browser. I provide a link to the user and when he clicks the link i
    >> want a file dialog to appear and the user can then give a file name to
    >> store those bytes as a file.
    >>
    >> The problem is i need to create links dynamically and supply the binary or
    >> image bytes as a file download to user. How can i do this?
    >>
    >> Can someone help me out here?
    >>
    >> Thanks in advance
    >> enzeez

    >
    >


    > I am sure your table will have a primary key and you will be using the
    > primary key to fetch the content
    >
    > 1) Link to some page like download.aspx and pass the key value (e.g. <a
    > href="download.aspx?fileid=1234">download</a>)
    > 2) In download.aspx codebehind, write code to retrieve the content for this
    > Id
    > 3) Write the resultset to using Response.binarywrite
    >
    > below is a asp code snippet which almost does the same.
    >
    > response.clear
    > response.contentType = "application/octet-stream"
    > response.addheader "content-disposition", "attachment; filename=" & FileName
    > set stream = server.CreateObject("ADODB.Stream")
    > stream.type = adTypeBinary
    > stream.open
    > stream.LoadFromFile Server.MapPath("/files") & FileName
    > while not stream.EOS
    > response.BinaryWrite Stream.Read(1024 * 64)
    > wend
    > stream.Close
    > Set stream = Nothing
    > response.Flush
    > response.End
    >
    >
    > Regards,
    > Augustin Prasanna
    >
    > "enzeez" <> wrote in message
    > news:u$...
    >> Hello,
    >>
    >> I have a record stored in sqlserver database in binary form.
    >> I want to display a link that will allow user to download this record as a
    >> File.
    >>
    >> I want to create a file at runtime or pass a specified number of bytes to
    >> user's browser. I provide a link to the user and when he clicks the link i
    >> want a file dialog to appear and the user can then give a file name to
    >> store those bytes as a file.
    >>
    >> The problem is i need to create links dynamically and supply the binary or
    >> image bytes as a file download to user. How can i do this?
    >>
    >> Can someone help me out here?
    >>
    >> Thanks in advance
    >> enzeez

    >
    >

    Thank you.
    This solves my problem
     
    enzeez, Apr 3, 2008
    #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. Jerry J
    Replies:
    2
    Views:
    767
    Jerry J
    Jul 20, 2003
  2. Robert Hanson
    Replies:
    3
    Views:
    664
    Steve C. Orr [MVP, MCSD]
    Nov 21, 2003
  3. =?Utf-8?B?b3o=?=

    Newbe question ---- response.writefile

    =?Utf-8?B?b3o=?=, Jan 9, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    304
    =?Utf-8?B?b3o=?=
    Jan 9, 2005
  4. Ryan Pedersen
    Replies:
    1
    Views:
    2,200
    Daniel Fisher\(lennybacon\)
    Jul 12, 2005
  5. =?Utf-8?B?bGFuZW0=?=

    Response.writefile question

    =?Utf-8?B?bGFuZW0=?=, Sep 29, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    428
    =?Utf-8?B?bGFuZW0=?=
    Sep 29, 2005
Loading...

Share This Page