Download image as normal file

Discussion in 'ASP .Net' started by Victor, May 17, 2007.

  1. Victor

    Victor Guest

    Hi.
    Is there a good way to let user can download image as a normal file? Like
    like the image then popup a messagebox ask user whether he want to save it
    or open it?

    Cheers
    Victor
     
    Victor, May 17, 2007
    #1
    1. Advertising

  2. Check out http://www.developer.com/net/net/article.php/3340151

    "Victor" wrote:

    > Hi.
    > Is there a good way to let user can download image as a normal file? Like
    > like the image then popup a messagebox ask user whether he want to save it
    > or open it?
    >
    > Cheers
    > Victor
    >
    >
    >
     
    =?Utf-8?B?U2l2YSBN?=, May 17, 2007
    #2
    1. Advertising

  3. Hi Victor,

    if you need to have the file downloaded from the ASP.NET site with a Save As
    dialog you can manipulate the headers. Basically you can send the file to
    the client yourself with Response.TransmitFile() and then add the
    appropriate Content-Type and Content-Disposition.

    Something like this:

    Response.ContentType = "image/jpg"
    Response.AppendHeader("Content-Disposition","attachment;
    filename=MyFile.jpg");
    Response.TransmitFile( Server.MapPath("~/images/MyFile.jpg") );


    +++ Rick ---

    --

    Rick Strahl
    West Wind Technologies
    www.west-wind.com/weblog


    "Victor" <> wrote in message
    news:...
    > Hi.
    > Is there a good way to let user can download image as a normal file? Like
    > like the image then popup a messagebox ask user whether he want to save it
    > or open it?
    >
    > Cheers
    > Victor
    >
     
    Rick Strahl [MVP], May 17, 2007
    #3
  4. Victor

    Spring Liu Guest

    On May 17, 1:04 pm, "Victor" <> wrote:
    > Hi.
    > Is there a good way to let user can download image as a normal file? Like
    > like the image then popup a messagebox ask user whether he want to save it
    > or open it?
    >
    > Cheers
    > Victor


    download.aspx:

    public partial class download : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    if (!IsPostBack)
    {
    string filePath = Server.MapPath("~") + "\\test.jpg";

    if (File.Exists(filePath))
    {
    Response.AddHeader("Content-Disposition", "attachment;
    filename=test.jpg"); // make sure keep this
    Response.TransmitFile(filePath);
    }
    else
    {
    Response.Write("No such file : " + filePath);
    }
    }

    }
    }

    Default.aspx:

    <a href="download.aspx?id=1">image link</a>

    hope helpful

    Spring
     
    Spring Liu, May 17, 2007
    #4
    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. Ryan Taylor
    Replies:
    2
    Views:
    974
    Ryan Taylor
    Nov 10, 2004
  2. Steve C. Orr [MVP, MCSD]
    Replies:
    0
    Views:
    1,637
    Steve C. Orr [MVP, MCSD]
    Mar 7, 2005
  3. Sam --
    Replies:
    2
    Views:
    633
    Sam --
    Mar 17, 2005
  4. Brett  Kelly
    Replies:
    1
    Views:
    692
    Steve C. Orr [MVP, MCSD]
    Jun 16, 2006
  5. Laszlo Zsolt Nagy
    Replies:
    1
    Views:
    1,380
    Kartic
    Jan 26, 2005
Loading...

Share This Page