0

I am trying to unzip a downloaded file with Ionic.Zip Dll.

My code works in a windows application but it wont work in my Web application.

The code runs with no errors but when i check the folder there is still the Ziped downloaded file with no extractions.

Is there any specificity things a web application needs to do this??

 private void MyExtract()
        {
            string zipToUnpack = "C:\\Users\\Shaun\\Desktop\\RescommTestData\\downloadfile.zip";
            string unpackDirectory = "ExtractedFiles"; //used to create a file to extract files to
            using (ZipFile zip1 = ZipFile.Read(zipToUnpack))
            {
                // here, we extract every entry, but we could extract conditionally
                // based on entry name, size, date, checkbox status, etc.  
                foreach (ZipEntry e in zip1)
                {
                    e.Extract(unpackDirectory, ExtractExistingFileAction.OverwriteSilently);
                    // e.Extract(ExtractExistingFileAction.OverwriteSilently);
                }

            }
            try
            {
                //File.Delete("C:\\Users\\Shaun\\Desktop\\downloadfile.zip");
                MessageBox.Show("Unpacked photos and data file into ExtractedFiles folder in bin/Debug");
            }
            catch (Exception)
            {
                MessageBox.Show("Could not delete ZIP!");
                Environment.Exit(1);
            }
tereško
  • 58,060
  • 25
  • 98
  • 150
Pomster
  • 14,567
  • 55
  • 128
  • 204
  • 3
    What isn't working? Does it throw the `Exception`? In that case please catch the `Exception` in a variable and post the value of the `Message` here. Have you checked file and folder rights? I can imagine that the web user doesn't have rights to your (or any other users) desktop folder. – Gerald Versluis Aug 22 '12 at 07:18
  • did you get any error messages or can you add more logging? maybe it's a rights issue? Windows7 is more strict about files from the web – mtijn Aug 22 '12 at 07:19
  • The extracted files may well be in your temporary ASP.Net folder; might be worth checking in there. There's also a good chance that, especially if you're using anonymous authentication, the website is unable to access the zip file on Shaun's desktop. – Euric Aug 22 '12 at 07:21
  • I'm pretty sure that IIS doesn't have permission to access to file on desktop. Move you file to c:\\Temp\ or temporary ASP.Net folder. – RredCat Aug 22 '12 at 07:21
  • 1
    shouldnt that `unpackDirectory` be a full path? Maybe its being extracted to some default location Temp folder maybe? – robasta Aug 22 '12 at 07:22
  • @GeraldVersluis no no exceptions no errors, the code runs but it does not do any thing, where in windows forms it would create a file called ExtractedFiles and unzip the download files contense into there. And no i have not checked rights, how would i do that? – Pomster Aug 22 '12 at 07:23
  • @rob where would this Temp folder be located? – Pomster Aug 22 '12 at 07:25
  • @RredCat Where is this temp folder created and how can i find it? – Pomster Aug 22 '12 at 07:26
  • 1
    to find your Temp folder, go to start, type in `%Temp%` – robasta Aug 22 '12 at 07:27
  • @Pommy have you tried searching you harddrive for the 'ExtractedFiles' folder? Because ASP.net is running somewhere else as a process, it might create a folder there. Try working witch a full path like 'C:\ExtractedFiles\' and see if that helps. The rights issue; ASP.net runs as a different user with lesser rights, so it cannot access every folder on the system. Create a folder, assign write rights to it (right click, Security tab, add the IISUSER_ (or some other user containing IIS I forgot and give him write rights) and try extracting the zip to there. – Gerald Versluis Aug 22 '12 at 07:28
  • @rob Thanks, would this Temp folder be the correct location to store my file, and would be Web application have the correct rights to access it? – Pomster Aug 22 '12 at 07:30
  • This might help: http://stackoverflow.com/questions/542312/asp-net-access-to-the-temp-directory-is-denied – Surfbutler Aug 22 '12 at 09:15

0 Answers0