image name
-
In my web project I need to show pictures using datalist. So when I set image source to let's say src='GetPicture.aspx?id=[id]' everything works fine, but when someone wants to save that picture it being saved as GetPicture.aspx, so user has to manually rename it afterwards to something.jpg. Is there a way to tell image name and extension? Thank you
-
In my web project I need to show pictures using datalist. So when I set image source to let's say src='GetPicture.aspx?id=[id]' everything works fine, but when someone wants to save that picture it being saved as GetPicture.aspx, so user has to manually rename it afterwards to something.jpg. Is there a way to tell image name and extension? Thank you
Hi there, You simply use the
filename
parameter of theContent-Disposition
header field to suggest a filename for the image. The sample code in theGetPicture.aspx
is simple like this:private void Page_Load(object sender, System.EventArgs e)
{
Response.Clear();byte\[\] bytes = GetImageContent(); Response.AddHeader("Content-Disposition", "filename=myphoto.jpg"); Response.OutputStream.Write(bytes, 0, bytes.Length); Response.End();
}
When you right click on the image and select
Save Picture As...
, the filenamemyphoto.jpg
will appear in the Save Picture dialog box. For more information, see Content-Disposition header field[^]. -
Hi there, You simply use the
filename
parameter of theContent-Disposition
header field to suggest a filename for the image. The sample code in theGetPicture.aspx
is simple like this:private void Page_Load(object sender, System.EventArgs e)
{
Response.Clear();byte\[\] bytes = GetImageContent(); Response.AddHeader("Content-Disposition", "filename=myphoto.jpg"); Response.OutputStream.Write(bytes, 0, bytes.Length); Response.End();
}
When you right click on the image and select
Save Picture As...
, the filenamemyphoto.jpg
will appear in the Save Picture dialog box. For more information, see Content-Disposition header field[^].