Thursday, February 26, 2015

Creating ZIP File

First download the dll Ionic.Zip from the following URL.

https://dotnetzip.codeplex.com/releases/view/68268

And, then add the dll( by Using Add Reference)

Design the form as follows:



<body>
    <form id="form1" runat="server">
    <div>
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <asp:Button ID="btnFileUpload" runat="server" Text="ZipFile" OnClick="btnFileUpload_Click" />
        <asp:Label ID="lblMessage" runat="server" Text=""></asp:Label>
    </div>
    </form>
</body>


Add, the following Namespace:

using Ionic.Zip;


protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnFileUpload_Click(object sender, EventArgs e)
    {
        try
        {
            string FileName = string.Empty;
            if (FileUpload1.HasFile)
            {
                FileName = FileUpload1.FileName;
                string path = Server.MapPath("~/Files/" + FileName);
                FileUpload1.SaveAs(path);
                ZipFile obj = new ZipFile();
                obj.AddFile(path);
                obj.Save(Server.MapPath("~/Files/File.zip"));
                lblMessage.Text = "Upload Successfully";
            }
        }
        catch (Exception)
        {
            throw;
        }

    }





output:





No comments:

Post a Comment

Thank you for visiting my blog

Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...