Tuesday, November 02, 2010

How to download images

Demo:
Code:
<%@ Page Language="C#" %>
<html>   
<head id="Head1" runat="server">  
    <script runat="server">
        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("~/Images/" + fileName));
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ImageButton runat="server" ID="btnPic1" Text="Pic 1" CommandArgument="Image1.jpg" 
            OnClick="DownloadPicture" Width="100" Height="75" ImageUrl="~/Images/Image1.jpg" />
        <asp:ImageButton runat="server" ID="btnPic2" Text="Pic 2" CommandArgument="Image2.jpg" 
            OnClick="DownloadPicture" Width="100" Height="75" ImageUrl="~/Images/Image2.jpg" />
        <asp:ImageButton runat="server" ID="btnPic3" Text="Pic 3" CommandArgument="Image3.jpg" 
            OnClick="DownloadPicture" Width="100" Height="75" ImageUrl="~/Images/Image3.jpg" />
        <asp:ImageButton runat="server" ID="btnPic4" Text="Pic 4" CommandArgument="Image4.jpg" 
            OnClick="DownloadPicture" Width="100" Height="75" ImageUrl="~/Images/Image4.jpg"/>
        <asp:ImageButton runat="server" ID="btnPic5" Text="Pic 5" CommandArgument="Image5.jpg" 
            OnClick="DownloadPicture" Width="100" Height="75" ImageUrl="~/Images/Image5.jpg"/>
    </form>
</body>
</html>

No comments:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...