Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET IsZipFile method by Xceed

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

    Hi,

    How can I check if a file is a zip file by Xceed dll (for C#)?

    (some method like:  bool IsZip(string filepath) of Xceed)

    Thanks,

    Roi 

    Imported from legacy forums. Posted by Roi (had 388 views)

    Fawzi [Xceed]
    Member
    Post count: 722

    Hi Roi,

     

    The component doesn’t have such a method. But you can write one yourself. Like so:

    static bool IsZipFile( AbstractFile file, out ZipArchive zip )
    {
      bool isZipFile = false;

      // If the file exists
      if( file.Exists )
      {
        try
        {
          // Try to wrap the zip file around a logical zip archive
          zip = new ZipArchive( file );
        }
        catch
        {
          // We weren’t able to create a zip archive around the zip file. It’s probably
          // not a zip file or the file is damaged
          zip = null;
          isZipFile = false;
        }

        // We were able to create a zip archive around the zip file. The archive object
        // is exported for efficiency
        isZipFile = true;
      }
      else
      {
        // The file doesn’t exist. So it’s certainly not an archive
        zip = null;
        isZipFile = false;
      }

      return isZipFile;
    }

    Imported from legacy forums. Posted by Fawzi [Xceed] (had 544 views)

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