473,569 Members | 2,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2840
You could make the button do a response.redire ct("insert path to image
here")

Michael

"David W. Simmonds" <da***@simmonds .ca> wrote in message
news:PzhQb.2449 02$X%5.43959@pd 7tw2no...
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************ ************@te levox.com> wrote in message
news:uV******** *****@TK2MSFTNG P12.phx.gbl...
You could make the button do a response.redire ct("insert path to image
here")

Michael

"David W. Simmonds" <da***@simmonds .ca> wrote in message
news:PzhQb.2449 02$X%5.43959@pd 7tw2no...
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 "ContentTyp e" and Header member. First we set the
Response.Conten tType 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.AddHea der 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.Conten tType = "Image/GIF";
Response.AddHea der( "Content-Disposition",
"attachment;fil ename=\"Microso ft.gif\"" );
Response.WriteF ile("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="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.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.P age
{
protected System.Web.UI.W ebControls.Butt on btnDownload;
protected System.Web.UI.W ebControls.Labe l lblMessage;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
}

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

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.btnDownloa d.Click += new
System.EventHan dler(this.btnDo wnload_Click);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

private void btnDownload_Cli ck(object sender, System.EventArg s e)
{
Response.ClearH eaders();
Response.ClearC ontent();
Response.Clear( );
Response.Conten tType = "Image/GIF";

Response.AddHea der("Content-Disposition","a ttachment;filen ame=\"MS.gif\"" );
Response.WriteF ile(Server.MapP ath("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.m icrosoft.com> wrote in message
news:AM******** ******@cpmsftng xa07.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 "ContentTyp e" and Header member. First we set the
Response.Conten tType 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.AddHea der 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.Conten tType = "Image/GIF";
Response.AddHea der( "Content-Disposition",
"attachment;fil ename=\"Microso ft.gif\"" );
Response.WriteF ile("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="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.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.P age
{
protected System.Web.UI.W ebControls.Butt on btnDownload;
protected System.Web.UI.W ebControls.Labe l lblMessage;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
}

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

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.btnDownloa d.Click += new
System.EventHan dler(this.btnDo wnload_Click);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

private void btnDownload_Cli ck(object sender, System.EventArg s e)
{
Response.ClearH eaders();
Response.ClearC ontent();
Response.Clear( );
Response.Conten tType = "Image/GIF";

Response.AddHea der("Content-Disposition","a ttachment;filen ame=\"MS.gif\"" ); Response.WriteF ile(Server.MapP ath("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
626
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" ); using ( Graphics g = Graphics.FromImage( inputImage ) ) { g.DrawLine( new Pen(Brushes.White), 0, 0, 1, 1 ); } inputImage.Save( @"c:\temp\sink.bmp",...
5
4005
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) { image =new Color*; for (int i=0;i<yres;i++)
9
2632
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 with a Bitmap the results are Black. Can you somehow Clip the Grafic and Paste it into the Bitmap ? Mark Johnson, Berlin Germany...
1
4341
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 http://home.foni.net/~sjost/fremd/IMGP5753-2.JPG I load the picture, and save it rotated by 270 degree. Works like charm: public void...
0
4121
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 as a image it uses image.Save method() This image.Save function have two overloaded form's first one is file name
1
4162
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 http://img140.imageshack.us/my.php?image=resized11wz.jpg). If I force to save in JPG format (see the commented line), then the whole shadow is a messup (see...
2
2642
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. ..../images/myPIC.jpg I wanted to draw a box or line using GDI+ on top of myPIC.jpg and then save the new image to the server.
1
6785
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 file during specific events in the script execution? image format doesnt matter. thanks! christine
1
3440
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 with this code it is often 4000-5000 kb.s. What am I missing? public class EmrTiff : IDisposable { private string fileName; private ArrayList...
0
2033
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 limited to what was taught in lectures. Right now I am making a GUI code and am having trouble saving the image after it has been altered. As of...
0
7694
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7609
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7921
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7666
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.