Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #20045 |

    Hi All,

     I’ve got the following loop in my code:

    Xceed.Zip.Licenser.LicenseKey = “XXXXXXX”;
    ZipArchive zipArchive = new ZipArchive(new DiskFile(“c:\\somefile.zip”));
    zipArchive.DefaultDecryptionPassword = “somepassword”;
    AbstractFile[] files = zipArchive.GetFiles(true, “*.*”);
    for (int i = 0; i < files.Length; i++)
    {
    AbstractFile destinationFile = new DiskFile(“C:\\temp\\” + files[ i ].Name);
    files[ i ].CopyTo(destinationFile, true);
    // do some processing here to see if the file should be kept… then…
    File.Copy(“C:\\temp\\” + files[ i ].Name“C:\\somepermanentplace\\” + files[ i ].Name, true);
    destinationFile.Delete();
    }

    The problem I’m having is that destinationFile.Delete() is throwing an exception because “the file is in use by another process”. I get where that is leading, but I can’t find the right place to call Close or Dispose to make sure the file is released. If someone understands the scoping of when OS file handles are opened and closed by the libraries, that’d be great to know (and, specifically, how the code above should be tweaked).

     Thanks in advance.

    Regards,

    Brian Eriksen

    Imported from legacy forums. Posted by Brian (had 936 views)

    Xceed Support
    Member
    Post count: 5658

    Hi, 

    I could not reproduce your problem but note that it is not recommended to use both the FileSystem and the File API.  You can instead create a Disfolder in which you can copy the destindationFile as follow:

     

    try

          {

            ZipArchive zipArchive = new ZipArchive( new DiskFile( @”D:\your_archive.zip” ) );

            //zipArchive.DefaultDecryptionPassword = “somepassword”;

            AbstractFile[] files = zipArchive.GetFiles( true, “*.*” );

            for( int i = 0; i < files.Length; i++ )

            {

              AbstractFile destinationFile = new DiskFile( “D:\\temp\\” + files[ i ].Name );

              files[ i ].CopyTo( destinationFile, true );

              // do some processing here to see if the file should be kept… then…

              AbstractFolder destinationFolder = new DiskFolder( “D:\\somepermanentplace\\” );

              destinationFile.CopyTo( destinationFolder,true );

              destinationFile.Delete();

            }

          }

          catch( Exception ex )

          {

            Console.WriteLine( ex.ToString() );

            Console.ReadLine();

          }

     

    Imported from legacy forums. Posted by Mohamed [Xceed] (had 1346 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.