473,396 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Download image as normal file

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
May 17 '07 #1
3 1412
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
May 17 '07 #2
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" <vi****@noemail.noemailwrote in message
news:OU**************@TK2MSFTNGP05.phx.gbl...
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
May 17 '07 #3
On May 17, 1:04 pm, "Victor" <vic...@noemail.noemailwrote:
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

May 17 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Aaron | last post by:
On my website I have a dynamic link(aspx) to this file 0AX120S.jpg(privacy protection). When a visitor clicks on the link I want them to see my_vacation_pic.jpg (fetch realname from database) is...
3
by: anastasia | last post by:
I get an out of memory exception when attempting to excecute the following code: original = System.Drawing.Image.FromFile(file.FileName,true); I ONLY get this exception when the file is in the...
8
by: kieran | last post by:
Hi, I want to download an image from the web and save it locally. I have spent all day messing about with this and am still no where. We have a firewall so i use the below code. I know it...
5
by: Baren | last post by:
Hi! I am using impersonate="true" to upload and download files from a network share. I have created common users on both the webserver and the file server. The user has permission to the...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
12
by: comp.lang.php | last post by:
index.php: // STUFF // STEP 1: imagecreatetruecolor ONLY IF GD 2.0+ SUPPORTED AND FOUND if ($this->isSuccessful && !$hasMogrified && $image && !$newImage &&...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
2
by: torbjorn.maro | last post by:
I'm the developer of an enterprise level web application that among other things handles documents. The documents are stored in a database. There is now simple functionality to check out and...
7
by: Sheldon Glickler | last post by:
I have a set of jpg files on a page. I want to give the user the option to downloadd all of them at once. What is the code to do that? It must exist because many times users are presented with a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.