Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does VB.NET use the FileVersionInfo class

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces VB.NET how to use FileVersionInfo class, the article is very detailed, has a certain reference value, interested friends must read it!

Have you ever wanted to know how to retrieve the properties of a specific file to use in your own application? If the application you are developing in VB.NET depends on a specific environment, you need to check the properties of the file before executing the code in the program. For example, you may need to know the product that comes with a particular file, or the version number of the file. In VB.NET, this information is easy to get with the help of the GetVersionInfo method and the FileVersionInfo class.

If you start Windows Explorer, right-click a file name, and then choose Properties from the pop-up menu, you will see the Properties window for that file. The Properties window displays information about the selected file. Suppose you right-click on the TASKMAN.EXE file name of the task manager.

Using the FileVersionInfo class with VB.NET, you can provide the same functionality in your VB.NET application. Depending on the needs of your application, you can copy all or some of the information displayed in the Properties dialog box.

To create a demo, start VB.NET and start a new project called Retrieving File Properties (retrieve file properties). Add seven text box controls, seven label controls, and a button control to Form1. Next, add the following code to the Click event of the Get Properties (get property) button:

Private Sub Button1_Click (ByVal sender _ As System.Object ByVal e As System.EventArgs) _ Handles Button1.Click 'get the file version of notepad Dim FileProperties As FileVersionInfoFileVersionInfo = FileVersionInfo.GetVersionInfo ("C:\ WINNT\ taskman.exe")' retrieve the file description (name) TextBox1.Text = FileProperties.FileDescription 'retrieve the file version TextBox2.Text = FileProperties.FileVersion' retrieve the internal name of the file TextBox3.Text = FileProperties.InternalName 'retrieve the old name of the file TextBox4.Text = FileProperties.OriginalFilename 'retrieve product name TextBox5.Text = FileProperties.ProductName' retrieve product version TextBox6.Text = FileProperties.ProductVersion 'search language TextBox7.Text = FileProperties.Language End Sub

Now, press F5 to execute the application. When you click the Get Properties button, the program displays information about the TASKMAN.EXE file.

The Click event code of the Get Properties (get property) button calls the GetVersionInfo method. This method returns a FileVersionInfo class that includes all version information for the file you specified. You need to provide a fully qualified file to the GetVersionInfo method. If the correct pathname is not specified, the method returns only the file name itself, not file information. After invoking GetVersionInfo, as we did in the demo, specific properties can be retrieved simply through the class.

The FileVersionInfo class contains a number of properties that you can query to retrieve file information. The following table shows only the properties we queried in the demo, but you can find the complete list in MSDN by searching the FileVersionInfo class description.

Attribute

Description

FileDescription

Retrieves the description of the specified file.

FileVersion

Retrieves the version number of the specified file.

InternalName

Retrieves the internal name of the specified file. (not all files are associated with internal names. )

OriginalFilename

Retrieves the name that the specified file was originally given when it was created.

ProductName

Retrieves the product name of the specified file. It is the name of the product that is released with this file. (not all files are associated with product names. )

ProductVersion

Retrieves the product version of the specified file. It is the version of the ProductName property.

Language

Retrieves the Microsoft language identifier (displayed as a string) in the version resource of the specified file.

Properties available to the FileVersionInfo class

The above is all the content of the article "how to use FileVersionInfo classes in VB.NET". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report