
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
742
|
Chapter 12: Filesystem I/O
12.25 Comparing Version Information
of Two Executable Modules
Problem
You need to programmatically compare the version information of two executable
modules. An executable module is a file that contains executable code such as an .exe
or .dll file. The ability to compare the version information of two executable mod-
ules can be very useful to an application in situations such as:
• Trying to determine if it has all of the “right” pieces present to execute
• Deciding on an assembly to dynamically load through reflection
• Looking for the newest version of a file or .dll from many files spread out in the
local filesystem or on a network
Solution
Use the CompareFileVersions method to compare executable module version infor-
mation. This method accepts two filenames, including their paths, as parameters.
The version information of each module is retrieved and compared. This file returns
a
FileComparison enumeration, defined as follows:
public enum FileComparison
{
Same = 0,
Newer = 1, // File1 is newer than File2
Older = 2, // File1 is older than File2
Error = 3
}
The code for the CompareFileVersions method is shown in Example 12-14.
Example 12-14. CompareFileVersions method
public static FileComparison CompareFileVersions(string file1, string file2)
{
FileComparison ...