views:

206

answers:

3

How do I get the version attribute of a file?

I tried the "Version" prop but it gives me the same number for all files

My Code:

 while (getNextEntry)
 {

    ZipEntry entry = inStream.GetNextEntry();

    getNextEntry = (entry != null);

    if (getNextEntry)
    {
     string fileType = Path.GetExtension(entry.Name);
     string version = "unavailable"; // entry.Version.ToString();
              // etc ...
     }
  }
A: 

Use FileVersionInfo.GetVersionInfo.

JP Alioto
I appreciate the quick answer, however, at this point I am just *reading* the ZipInputStream. That would definitely work for *after* the file has been unzipped.is there no way a file version can be read while still sitting in the zip file?
KevinDeus
A: 

This is correct behavior. I am not familiar with SharpZipLib, but in .zip format itself, field version contains version of PkZip software needed to extract this particular file (or version of software that created this file). And, as usually, entire zip file created with one tool, so such field will contain the same version.

Again, version in zip is not file version, but version of software that packed this file.

You can read more about zip format here (Main source of information about zip format).

arbiter
A: 

The version in the zip entry is the "version needed to extract", and it refers to the version of the ZIP spec that the unzipping tool must support, in order to properly extract that entry. This is different than the version of the tool that packed the zip. Also, this number is often the same for all entries in a zip archive, but that isn't a requirement. Different entries can have different features enabled - the most common variations are encryption and zip64 encoding. The first entry may be unencrypted in which case the version-needed-to-extract will be 20. The next entry may use zip64 extensions, in which case the version-needed-to-extract will be 45.

This version number is mostly interesting when building a tool or libbrary that packs or unpacks zips. If you are using a zip library, you shouldn't have to care about it. The library should take care of it for you.

Cheeso