ScruffyDuck
ScruffyDuck

Reputation: 2666

Get Version from Non Executing Executable File

I know how to get the version of an executing application or dll. However I need to find the properties of a non executing application.

I have a small program to set a file association for my main application. There is no point in users of old versions running this since the application does not accept arguments on start up. So when the file associator starts it first checks to see if it can find the main app. If it can then I want to check the properties without executing it. If the version is earlier than one that can accept arguments then I want to tell my user to update rather than proceed to set the association.

I have looked at System.IO.FileInfo but that does not seem to include any Version information.

Thanks

Upvotes: 7

Views: 2802

Answers (1)

Aliostad
Aliostad

Reputation: 81700

You can use FileVersionInfo.GetVersionInfo():

FileVersionInfo vi = FileVersionInfo.GetVersionInfo("myfile.dll");

string showVersion = vi.FileVersion;

//showVersion is the actual version No.

This returns file/document metadata and can be used for unmanaged DLLs or even word documents as well.

You can also use Assembly:

Version v = Assembly.ReflectionOnlyLoadFrom("myfile.dll").GetName().Version;

This will contain .NET version information.

Upvotes: 13

Related Questions