Thursday, June 24, 2010

How to download a image using c# - Asp.net

Download a image we have to set file attachment and content type of the response.
Demo:
Example:
public void DownloadPicture(object sender, EventArgs e)
{
    ImageButton button = sender as ImageButton;
    if (button != null)
    {
        string fileName = button.CommandArgument;
        this.Response.AddHeader(
            "content-disposition"string.Format(
            "attachment;filename={0}"Path.GetFileName(fileName)));
        this.Response.ContentType = "image/jpg";
        this.Response.WriteFile(this.Server.MapPath(fileName));
    }
}

No comments:

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...