Creating FileVersionInfo Objects

This section provides a tutorial example on how to create a FileVersionInfo object to represent the version information of a specific executable file.

If you read the reference of FileVersionInfo class, you will see no constructor method provided in the FileVersionInfo class.

Without a constructor method, how can you create a FileVersionInfo object? The answer is to use the static method called GetVersionInfo().

GetVersionInfo(fileName) is a static method that returns a FileVersionInfo object representing the version information stored with the specified file. "fileName" is a string representation of the path name of the specified file.

Here is a quick sample C# program that shows you how to use the FileVersionInfo.GetVersionInfo() static method.

// FileVersionInfoTest.cs
// Copyright (c) All Rights Reserved.

using System;
using System.Diagnostics;
public class FileVersionInfoTest {
   public static void Main() {

      // Creating the FileVersionInfo object to represent cmd.exe
      FileVersionInfo cmdVersion
         = FileVersionInfo.GetVersionInfo("C:\\Windows\\System32\\cmd.exe");

      // Printing out version information of cmd.exe
      Console.WriteLine("File name: {0}", cmdVersion.FileName);
      Console.WriteLine("File description: {0}",
      Console.WriteLine("File version: {0}", cmdVersion.FileVersion);

Compile it with .NET SDK 4.6.1 and run it:



File name: C:\Windows\System32\cmd.exe
File description: Windows Command Processor
File version: 6.1.7601.17514 (win7sp1_rtm.101119-1850)

It works!

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

 Outdated Tutorials


 Full Version in PDF/ePUB