ShowFileVersionInfo.cs - Print File Version Information

This section provides a tutorial example on how to use the FileVersionInfo class to print out all properties included in the version information of an executable file.

In the previous section, we learned how to create a FileVersionInfo object to represent the version information of a specific executable file.

Now let's write a more useful program to dump all properties related to the version information of a given file:

// ShowFileVersionInfo.cs
// Copyright (c) 2016 HerongYang.com. All Rights Reserved.

using System;
using System.Diagnostics;
public class ShowFileVersionInfo {
   public static void Main(string[] args) {

      // Getting file path name from command line
      if (args.Length < 1) {
         Console.WriteLine("Usage: ShowFileVersionInfo fullPath");
         return;
      }
      string fileName = args[0];

      // Creating the FileVersionInfo object
      FileVersionInfo cmdVersion
         = FileVersionInfo.GetVersionInfo(fileName);

      // Printing out file name information
      Console.WriteLine();
      Console.WriteLine("File name information:");
      Console.WriteLine("   File name: {0}", cmdVersion.FileName);
      Console.WriteLine("   Internal name: {0}",
         cmdVersion.InternalName);
      Console.WriteLine("   Original file name: {0}",
         cmdVersion.OriginalFilename);
      Console.WriteLine("   File description: {0}",
         cmdVersion.FileDescription);

      // Printing out file version information
      Console.WriteLine();
      Console.WriteLine("File version information:");
      Console.WriteLine("   File version: {0}",
         cmdVersion.FileVersion);
      Console.WriteLine("   File major part: {0}",
         cmdVersion.FileMajorPart);
      Console.WriteLine("   File minor part: {0}",
         cmdVersion.FileMinorPart);
      Console.WriteLine("   File build part: {0}",
         cmdVersion.FileBuildPart);
      Console.WriteLine("   File private part: {0}",
         cmdVersion.FilePrivatePart);

      // Printing out product information
      Console.WriteLine();
      Console.WriteLine("Product information:");
      Console.WriteLine("   Product name: {0}",
         cmdVersion.ProductName);
      Console.WriteLine("   Product version: {0}",
         cmdVersion.ProductVersion);
      Console.WriteLine("   Product major part: {0}",
         cmdVersion.ProductMajorPart);
      Console.WriteLine("   Product minor part: {0}",
         cmdVersion.ProductMinorPart);
      Console.WriteLine("   Product build part: {0}",
         cmdVersion.ProductBuildPart);
      Console.WriteLine("   Product private part: {0}",
         cmdVersion.ProductPrivatePart);

      // Printing out other information
      Console.WriteLine();
      Console.WriteLine("Other information:");
      Console.WriteLine("   Company name: {0}",
         cmdVersion.CompanyName);
      Console.WriteLine("   Legal copyright: {0}",
         cmdVersion.LegalCopyright);
      Console.WriteLine("   Legal trademarks: {0}",
         cmdVersion.LegalTrademarks);
      Console.WriteLine("   Private build: {0}",
         cmdVersion.PrivateBuild);
      Console.WriteLine("   Special build: {0}",
         cmdVersion.SpecialBuild);
      Console.WriteLine("   Comments: {0}", cmdVersion.Comments);
   }
}

Compile it with .NET SDK 4.0 and run it:

C:\herong>\windows\Microsoft.NET\Framework\v4.0.30319\csc
   ShowFileVersionInfo.cs

C:\herong>ShowFileVersionInfo C:\Windows\system32\cmd.exe

File name information:
   File name: C:\Windows\system32\cmd.exe
   Internal name: cmd
   Original file name: Cmd.Exe.MUI
   File description: Windows Command Processor

File version information:
   File version: 6.1.7601.17514 (win7sp1_rtm.101119-1850)
   File major part: 6
   File minor part: 1
   File build part: 7601
   File private part: 17514

Product information:
   Product name: Microsoft Windows Operating System
   Product version: 6.1.7601.17514
   Product major part: 6
   Product minor part: 1
   Product build part: 7601
   Product private part: 17514

Other information:
   Company name: Microsoft Corporation
   Legal copyright: c Microsoft Corporation. All rights reserved.
   Legal trademarks:
   Private build:
   Special build:
   Comments:

Note that:

Table of Contents

 About This Book

 Introduction of C# (C Sharp)

 Data Type and Variables

 Logical Expressions and Conditional Statements

 Arrays and Loop Statements

 Data Type Features

 Floating-Point Data Types

 Passing Parameters to Methods

 Execution Environment Class

 Visual C# 2010 Express Edition

 Class Features

 C# Compiler and Intermediate Language

 Compiling C# Source Code Files

 MSBuild - Microsoft Build Engine

 Memory Usages of Processes

 Multithreading in C#

 Async Feature from C# 5

 System.IO.FileInfo Class

System.Diagnostics.FileVersionInfo Class

 What Is FileVersionInfo?

 Public Properties of FileVersionInfo Class

 Creating FileVersionInfo Objects

ShowFileVersionInfo.cs - Print File Version Information

 Displaying Version Information using Windows Explorer

 Displaying Version Information using PE Explorer

 WPF - Windows Presentation Foundation

 Partial Classes and Partial Methods

 Archived Tutorials

 References

 Full Version in PDF/ePUB