473,395 Members | 1,702 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,395 software developers and data experts.

Save Image

Is there a way I can have a button on a ASP.NET form that when clicked will
allow the user to save the image to a file on the client side? I know that
the user can simply rclick the image and select Save Target as..., but the
button might be a more intuitive way.
Nov 18 '05 #1
4 2828
You could make the button do a response.redirect("insert path to image
here")

Michael

"David W. Simmonds" <da***@simmonds.ca> wrote in message
news:PzhQb.244902$X%5.43959@pd7tw2no...
Is there a way I can have a button on a ASP.NET form that when clicked will allow the user to save the image to a file on the client side? I know that
the user can simply rclick the image and select Save Target as..., but the
button might be a more intuitive way.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.564 / Virus Database: 356 - Release Date: 1/19/2004
Nov 18 '05 #2
That just brings up another instance of the image in the window. It does not
prompt the user to save it. Does anyone know how I might do this or am I
stuck with the standard method of having the user rclick the image and
select from the menu?

"Michael Pearson" <mi************************@televox.com> wrote in message
news:uV*************@TK2MSFTNGP12.phx.gbl...
You could make the button do a response.redirect("insert path to image
here")

Michael

"David W. Simmonds" <da***@simmonds.ca> wrote in message
news:PzhQb.244902$X%5.43959@pd7tw2no...
Is there a way I can have a button on a ASP.NET form that when clicked

will
allow the user to save the image to a file on the client side? I know that the user can simply rclick the image and select Save Target as..., but the button might be a more intuitive way.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.564 / Virus Database: 356 - Release Date: 1/19/2004

Nov 18 '05 #3
Hi David,
Thanks for posting in the community! My name is Steven, and I'll be
assisting you on this issue.
From your description, you'd like to let the user manually click a button
to download a certain image file. Just like they use the "save as" menu in
the IE's content menu ,yes?
If there is anything I misunderstood, please feel free to let me know.

As for this problem, I think we can implement this by setting the page's
Response object's "ContentType" and Header member. First we set the
Response.ContentType as "Image/GIF" or "Image/JPEG" to specify the response
stream as a image. Then, add a Header item into the response using the
Response.AddHeader method to streaming the image as an attachment to the
browser , then in the client the browser will popup a dialog to let the
user choose open or save the certain file. For example:

Response.ContentType = "Image/GIF";
Response.AddHeader( "Content-Disposition",
"attachment;filename=\"Microsoft.gif\"" );
Response.WriteFile("Microsoft.gif"); // write the file to the response
stream

Also, here is an sample page, you may have a try on it:
-----------------------aspx page-----------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Download</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td><FONT face="ËÎÌå">
<asp:Label id="lblMessage" runat="server" Text="Click the button to
download the image!"></asp:Label></FONT></td>
</tr>
<tr>
<td>
<asp:Button id="btnDownload" runat="server"
Text="Download"></asp:Button></td>
</tr>
</table>
</form>
</body>
</HTML>
-----------------------code behind page class----------------------

public class Download : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnDownload;
protected System.Web.UI.WebControls.Label lblMessage;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnDownload.Click += new
System.EventHandler(this.btnDownload_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnDownload_Click(object sender, System.EventArgs e)
{
Response.ClearHeaders();
Response.ClearContent();
Response.Clear();
Response.ContentType = "Image/GIF";

Response.AddHeader("Content-Disposition","attachment;filename=\"MS.gif\"");
Response.WriteFile(Server.MapPath("MS.gif"));
Response.End();
}
}

If you have any further questions, please feel free to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #4
That works great. Thanks.

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:AM**************@cpmsftngxa07.phx.gbl...
Hi David,
Thanks for posting in the community! My name is Steven, and I'll be
assisting you on this issue.
From your description, you'd like to let the user manually click a button
to download a certain image file. Just like they use the "save as" menu in
the IE's content menu ,yes?
If there is anything I misunderstood, please feel free to let me know.

As for this problem, I think we can implement this by setting the page's
Response object's "ContentType" and Header member. First we set the
Response.ContentType as "Image/GIF" or "Image/JPEG" to specify the response stream as a image. Then, add a Header item into the response using the
Response.AddHeader method to streaming the image as an attachment to the
browser , then in the client the browser will popup a dialog to let the
user choose open or save the certain file. For example:

Response.ContentType = "Image/GIF";
Response.AddHeader( "Content-Disposition",
"attachment;filename=\"Microsoft.gif\"" );
Response.WriteFile("Microsoft.gif"); // write the file to the response
stream

Also, here is an sample page, you may have a try on it:
-----------------------aspx page-----------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Download</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td><FONT face="ËÎÌå">
<asp:Label id="lblMessage" runat="server" Text="Click the button to
download the image!"></asp:Label></FONT></td>
</tr>
<tr>
<td>
<asp:Button id="btnDownload" runat="server"
Text="Download"></asp:Button></td>
</tr>
</table>
</form>
</body>
</HTML>
-----------------------code behind page class----------------------

public class Download : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnDownload;
protected System.Web.UI.WebControls.Label lblMessage;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnDownload.Click += new
System.EventHandler(this.btnDownload_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnDownload_Click(object sender, System.EventArgs e)
{
Response.ClearHeaders();
Response.ClearContent();
Response.Clear();
Response.ContentType = "Image/GIF";

Response.AddHeader("Content-Disposition","attachment;filename=\"MS.gif\""); Response.WriteFile(Server.MapPath("MS.gif"));
Response.End();
}
}

If you have any further questions, please feel free to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Nov 18 '05 #5

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

Similar topics

0
by: F. Hall | last post by:
If I read a bitmap image from one file and save it to another the save operation is slow unless I draw on the image. In other words, Image inputImage = Image.FromFile( @"c:\temp\source.bmp" );...
5
by: George | last post by:
This program need to draw the some triangles into a 512 × 512 buffer (in memory). Or save it to a file. #include "project3.h" Image::Image(int xres, int yres): xres(xres), yres(yres) {...
9
by: Mark Johnson | last post by:
How can you save all or a portion of the Grafics object to a Image/Bitmap ? I am try to save the Images from Cards.dll to a BitMap file. I can read in the Images to the Grafics, but when I try this...
1
by: Sam Jost | last post by:
Bitmap.Save() does crash very often on Saving jpg's. It seems to dislike pictures on a random basis, but when it dislikes a picture there is no way around it. Take for example the picture...
0
by: prakash | last post by:
Dear Friends I am new guy to Visual C++.NET I've program to save website as a image vc++.net . It have a function "SaveSnapshot" to save the webpage as an image On that function ifor saving...
1
by: Hardy Wang | last post by:
Hi, I found a piece of code to add drop shadow to a photo like below, after I save the image, it is actually a BMP file even though I specify a JPG file extension (see...
2
by: Ada | last post by:
First of all, I thought this might be a directory security issue but it's not. I was able to upload the file to the directory via HTTP. Here's the situation. I have a JPG file on my server....
1
by: liuliuliu | last post by:
hi -- sorry if this is trivial -- but how do you make a screenshot of a pygame display? i have a surface which is basically the entire visible screen -- how do you write this surface as an image...
1
by: Stedak | last post by:
I have the following class I use to save Tiff's. The problem I have with it is that the final size of the images are very large. If we scan directly to a file the final tiff may be 600-900 kb.s but...
0
by: crazyyellowguy | last post by:
hi, This is my first post in this forum and I just wanted to thank you for even taking a look at my post. The class that I am writing the C code for is my first computer class and my knowledge is...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.