Upload a zip file then extract files on server

4 posts, 0 answers
  1. Tracey
    Tracey avatar
    34 posts
    Member since:
    Feb 2011

    Posted 14 Nov 2011 Link to this post

    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
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 17 Nov 2011 Link to this post

    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 >>

  3. Tracey
    Tracey avatar
    34 posts
    Member since:
    Feb 2011

    Posted 17 Nov 2011 Link to this post

    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
  4. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 22 Nov 2011 Link to this post

    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 >>

Back to Top