Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Download image as normal file

Reply
Thread Tools

Download image as normal file

 
 
Victor
Guest
Posts: n/a
 
      05-17-2007
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?U2l2YSBN?=
Guest
Posts: n/a
 
      05-17-2007
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
>
>
>

 
Reply With Quote
 
 
 
 
Rick Strahl [MVP]
Guest
Posts: n/a
 
      05-17-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>


 
Reply With Quote
 
Spring Liu
Guest
Posts: n/a
 
      05-17-2007
On May 17, 1:04 pm, "Victor" <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Forcing Download of File Appends HTML from Download Page to Downloaded File? Brett Kelly ASP .Net 1 06-16-2006 04:05 AM
Is this download speed fluctuation normal? mentalguy2004 Computer Support 3 05-03-2006 07:22 PM
problem with code download file - two window file download Sam -- ASP .Net 2 03-17-2005 04:20 PM
File upload/download from database. Download appends aspx page to end of file Ryan Taylor ASP .Net 2 11-10-2004 08:31 PM



Advertisments