Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Zip files

Zip files

Scheduled Pinned Locked Moved C#
help
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DinoRondelly
    wrote on last edited by
    #1

    I am generating a zip file and then emailing it. I am using a temp directory to create this file but i will always be creating a number of different files using this directory. The problem i am having is when i go to delete the files inside my temp directory i get an error saying that the zip file is being used by another process. I have stepped through the code and waited until the email was sent to be sure that its not being locked there. I have also set the zipfile to null and that still didnt work. if anyone has any ideas as to what might be causing this i would be forever grateful.

                        if (!CreatedTempFolder)
                        {
                            //if not dir exists
                            if (!System.IO.Directory.Exists(TempFileLocation))
                                // create it
                                System.IO.Directory.CreateDirectory(TempFileLocation);
                            else
                            {
                                //delete all files from temp foleder
                                    System.IO.Directory.Delete(TempFileLocation, true);
                                    System.IO.Directory.CreateDirectory(TempFileLocation);
                            }
                            //set CreatedTempFolder to true
    
    
                    string zipFileName = string.Format("{0}\\\\{1}.zip", TempFileLocation, DrSched\["GROUPNAME"\].ToString());
                    MyZip zipfile = new MyZip(zipFileName,"W");
                    
    
                    foreach (string fileName in System.IO.Directory.GetFiles(TempFileLocation,"\*.csv"))
                        zipfile.AddFile(fileName);
    
                    //zipfile.Save();
                    zipfile.Close();
    
                    zipfile = null;
                    GC.Collect();
    
    J T L 3 Replies Last reply
    0
    • D DinoRondelly

      I am generating a zip file and then emailing it. I am using a temp directory to create this file but i will always be creating a number of different files using this directory. The problem i am having is when i go to delete the files inside my temp directory i get an error saying that the zip file is being used by another process. I have stepped through the code and waited until the email was sent to be sure that its not being locked there. I have also set the zipfile to null and that still didnt work. if anyone has any ideas as to what might be causing this i would be forever grateful.

                          if (!CreatedTempFolder)
                          {
                              //if not dir exists
                              if (!System.IO.Directory.Exists(TempFileLocation))
                                  // create it
                                  System.IO.Directory.CreateDirectory(TempFileLocation);
                              else
                              {
                                  //delete all files from temp foleder
                                      System.IO.Directory.Delete(TempFileLocation, true);
                                      System.IO.Directory.CreateDirectory(TempFileLocation);
                              }
                              //set CreatedTempFolder to true
      
      
                      string zipFileName = string.Format("{0}\\\\{1}.zip", TempFileLocation, DrSched\["GROUPNAME"\].ToString());
                      MyZip zipfile = new MyZip(zipFileName,"W");
                      
      
                      foreach (string fileName in System.IO.Directory.GetFiles(TempFileLocation,"\*.csv"))
                          zipfile.AddFile(fileName);
      
                      //zipfile.Save();
                      zipfile.Close();
      
                      zipfile = null;
                      GC.Collect();
      
      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      If MyZip implements IDisposable (which Im willing to bet it does!) then you need to call Dispose() on it. Setting it to null does nothing to solve the problem you're experiencing.

      1 Reply Last reply
      0
      • D DinoRondelly

        I am generating a zip file and then emailing it. I am using a temp directory to create this file but i will always be creating a number of different files using this directory. The problem i am having is when i go to delete the files inside my temp directory i get an error saying that the zip file is being used by another process. I have stepped through the code and waited until the email was sent to be sure that its not being locked there. I have also set the zipfile to null and that still didnt work. if anyone has any ideas as to what might be causing this i would be forever grateful.

                            if (!CreatedTempFolder)
                            {
                                //if not dir exists
                                if (!System.IO.Directory.Exists(TempFileLocation))
                                    // create it
                                    System.IO.Directory.CreateDirectory(TempFileLocation);
                                else
                                {
                                    //delete all files from temp foleder
                                        System.IO.Directory.Delete(TempFileLocation, true);
                                        System.IO.Directory.CreateDirectory(TempFileLocation);
                                }
                                //set CreatedTempFolder to true
        
        
                        string zipFileName = string.Format("{0}\\\\{1}.zip", TempFileLocation, DrSched\["GROUPNAME"\].ToString());
                        MyZip zipfile = new MyZip(zipFileName,"W");
                        
        
                        foreach (string fileName in System.IO.Directory.GetFiles(TempFileLocation,"\*.csv"))
                            zipfile.AddFile(fileName);
        
                        //zipfile.Save();
                        zipfile.Close();
        
                        zipfile = null;
                        GC.Collect();
        
        T Offline
        T Offline
        The Man from U N C L E
        wrote on last edited by
        #3

        You haven't stated what zipFile is (build in .Net functionality? sharpZipLib? Other third party?) however I suspect the problem is you need to call Dispose as well as Close, so that it releases unmanaged resources, in this case the underlying file.

        If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

        D 1 Reply Last reply
        0
        • T The Man from U N C L E

          You haven't stated what zipFile is (build in .Net functionality? sharpZipLib? Other third party?) however I suspect the problem is you need to call Dispose as well as Close, so that it releases unmanaged resources, in this case the underlying file.

          If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

          D Offline
          D Offline
          DinoRondelly
          wrote on last edited by
          #4

          Thanks for your help i have found a work around from this i am still not 100% sure exactly what MyZip(its company specific). Thanks for all your help !!! Dino

          1 Reply Last reply
          0
          • D DinoRondelly

            I am generating a zip file and then emailing it. I am using a temp directory to create this file but i will always be creating a number of different files using this directory. The problem i am having is when i go to delete the files inside my temp directory i get an error saying that the zip file is being used by another process. I have stepped through the code and waited until the email was sent to be sure that its not being locked there. I have also set the zipfile to null and that still didnt work. if anyone has any ideas as to what might be causing this i would be forever grateful.

                                if (!CreatedTempFolder)
                                {
                                    //if not dir exists
                                    if (!System.IO.Directory.Exists(TempFileLocation))
                                        // create it
                                        System.IO.Directory.CreateDirectory(TempFileLocation);
                                    else
                                    {
                                        //delete all files from temp foleder
                                            System.IO.Directory.Delete(TempFileLocation, true);
                                            System.IO.Directory.CreateDirectory(TempFileLocation);
                                    }
                                    //set CreatedTempFolder to true
            
            
                            string zipFileName = string.Format("{0}\\\\{1}.zip", TempFileLocation, DrSched\["GROUPNAME"\].ToString());
                            MyZip zipfile = new MyZip(zipFileName,"W");
                            
            
                            foreach (string fileName in System.IO.Directory.GetFiles(TempFileLocation,"\*.csv"))
                                zipfile.AddFile(fileName);
            
                            //zipfile.Save();
                            zipfile.Close();
            
                            zipfile = null;
                            GC.Collect();
            
            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            If you are targeting .NET 3.5 or even 4.0 there is a namespace called System.IO.Packaging , which contains some classes that allow working with zip files. :)

            Life is a stage and we are all actors!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups