This is a migrated thread and some comments may be shown as answers.

Upload a zip file then extract files on server

3 Answers 279 Views
ZipLibrary
This is a migrated thread and some comments may be shown as answers.
Tracey
Top achievements
Rank 1
Tracey asked on 14 Nov 2011, 04:56 PM
Hi

I want to be able to upload a zip file to the server (using RadUpload) and then extract the files within it to the server once uploaded.

How do i do this?

Many Thanks
Tracey

3 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 17 Nov 2011, 01:22 PM
Hi Tracey,

I attached a sample solution demonstrating a possible approach towards your scenario. Please give it a try and let me know if it works for you.

Regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Tracey
Top achievements
Rank 1
answered on 17 Nov 2011, 06:28 PM
Hi Tina

Using a RadUploadHandler (almost) works a treat. I have some xml files in the folder I am unzipping and it doesn't create them correctly, it adds a lot more data to the files (as if it's writing the entire folder contents to the file - see jpg in link Unzipped Xml File).

from what I tested the rest - folders, .mp3, .mp4, .jpg, .png all unzipped correctly

Cheers
0
Tina Stancheva
Telerik team
answered on 22 Nov 2011, 06:28 PM
Hello Tracey,

I can't reproduce this issue on our side. Can you reproduce it using the sample solution attached here? If you can, then the cause might be in the content of the archives you upload and/or the content of the xml files that have to be extracted on the server.

This is why I wanted to ask you to please send us a support ticket and attach the zip file that you use to reproduce the issue on our side. This way we will be able to test it here as well.

Also, you can try modifying the SaveFile() method:
//Save the unzipped files
private static void SaveFile(ZipPackageEntry entry, string destinationPath)
{
    Stream stream = entry.OpenInputStream();
    var fileName = destinationPath + "\\" + entry.FileNameInZip;
 
    var directoryName = Path.GetDirectoryName(fileName);
 
    if (directoryName != null)
    {
        if (!Directory.Exists(directoryName))
        {
            Directory.CreateDirectory(directoryName);
        }
 
        StreamReader reader = new StreamReader(stream);
        string text = reader.ReadToEnd();
        File.WriteAllText(fileName, text);
    }
}
to see if the issue is still reproducible.

Thank you in advance for your cooperation on the matter.

Best wishes,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
ZipLibrary
Asked by
Tracey
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Tracey
Top achievements
Rank 1
Share this question
or