Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET Zip Files from FTP in Stream

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

    Hi All,

    I am trying add multiple files to ZipArchive by getting each file from FTP. This works fine while adding a single file. But getting the below exception when trying to add multiple files:

    An exception of type ‘Xceed.FileSystem.ItemDoesNotExistException’ occurred in Xceed.FileSystem.DLL but was not handled in user code

    Additional information: Cannot perform the requested operation on an item that does not exist.

    Please help with this. 

    Also if possibe can anyone provide me sample code for how to add multiple files to stream and zip it?

    Imported from legacy forums. Posted by Ajay (had 1241 views)

    Xceed Support
    Member
    Post count: 5658

    Before opening a stream on a file, you need to be sure that the file does exist. Here is an example where we stream some files (individually) from a FtpFolder into a zip archive. 

    using( FtpConnection connection = new FtpConnection( “http://ftp.xceed.com“, “anonymous”, “guest” ) )
    {
      AbstractFile zipFile = new DiskFile( @”D:\Forum12011\archive.zip” );

      FtpFolder ftpFolder = new FtpFolder( connection );

      AbstractFile[] files = ftpFolder.GetFiles( false );

      foreach( AbstractFile file in files )
      {
        using( Stream source = file.OpenRead() )
        {
          ZippedFile zippedFile = new ZippedFile( zipFile, file.Name );
          if( !zippedFile.Exists )
            zippedFile.Create();

          using( Stream destination = zippedFile.OpenWrite( true ) )
          {
            byte[] buffer = new byte[ 1024 ];
            int bytesRead = 0;
            while( ( bytesRead = source.Read( buffer, 0, buffer.Length ) ) > 0 )
            {
              destination.Write( buffer, 0, bytesRead );
            }
          }
        }
      }
    }

    Imported from legacy forums. Posted by CharlesB (had 1346 views)

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