Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component

Index of Chilkat Blog Posts

December 7, 2006

Creating Zip Files on your ASP.NET Server

Creating files from ASP.NET (C# or VB.NET) can be a pain, with directory permissions getting in the way…

Here is a C# example that shows how to create a .zip file in a "ZipFiles" subdirectory beneath the application root. You’ll first need to create the directory and then give it Write permission. Once you do it, the following code should work:

    private string MappedApplicationPath()
            string APP_PATH = System.Web.HttpContext.Current.Request.ApplicationPath.ToLower();
            if (APP_PATH == "/")      //a site
                APP_PATH = "/";
            else if (!APP_PATH.EndsWith(@"/")) //a virtual
                APP_PATH += @"/";
            string it = System.Web.HttpContext.Current.Server.MapPath(APP_PATH);
            if (!it.EndsWith(@"\"))
                it += @"\";
            return it;
    // This example creates a Zip file in a "ZipFiles" directory under
    // the application root directory.  You should first provide write access
    // to the ZipFiles directory before running this sample.
    protected void Button1_Click(object sender, EventArgs e)
        Chilkat.Zip zip = new Chilkat.Zip();
        zip.UnlockComponent("anything for 30-day trial");
        string mappedPath = MappedApplicationPath();
        zip.TempDir = mappedPath + "ZipFiles";
        zip.NewZip(mappedPath + "ZipFiles\\");
        zip.AppendAnsi("test.txt", "this is a test");
        TextBox1.Text = zip.LastErrorText;

Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.