user959631
user959631

Reputation: 992

Unzipping a file that is on the server in asp.net

I want the user to be able to upload a folder to my server, but I read that this can't be done, but if you change it to a .zip file, then upload the .zip file like normal. I searched in some places and couldn't find out how to do it in asp.net (VB). Can anyone lead me in the correct direction? I haven't a clue about how to do this, otherwise I would have provided some code. My Question: How would I go about unzipping a .zip file that is on the server in asp.net?

Thanks in advance.

Upvotes: 0

Views: 2927

Answers (2)

David
David

Reputation: 73594

There's a step-by-step walkthrough in unzipping files using c# here. It's a WinForms example, but doing it in code-behind in asp.net is no different than WinForms

Fair warning, though, that a .zip file can contain anything, and you need to prevent against malicious file execution.

Upvotes: 4

Ashkan Mobayen Khiabani
Ashkan Mobayen Khiabani

Reputation: 34180

This example is using System.IO.Compression.ZipFile, from Microsoft Documents:

using System;
using System.IO;
using System.IO.Compression;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            string startPath = @"c:\example\start";
            string zipPath = @"c:\example\result.zip";
            string extractPath = @"c:\example\extract";

            ZipFile.CreateFromDirectory(startPath, zipPath);

            ZipFile.ExtractToDirectory(zipPath, extractPath);
        }
    }
}

Upvotes: 1

Related Questions