FileVersionInfo类显示dll信息

 本文通过该类,获取DLL的基本信息,包括厂商,描述,guid等等信息。

下面是简单的实例:

public static void Main(string[] args) { // Get the file version for the notepad. FileVersionInfo.GetVersionInfo(Path.Combine(Environment.SystemDirectory, "Notepad.exe")); FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(Environment.SystemDirectory + "//Notepad.exe"); // Print the file name and version number. Console.WriteLine("File: " + myFileVersionInfo.FileDescription + '/n' + "Version number: " + myFileVersionInfo.FileVersion); } }

 

 

 

我需要通过FileVersionInfo获取系统目录下的dll文件信息。

如下:

 

private DataTable GetDLLtoDatatable() { DataTable dt = new DataTable(); DataColumnCollection dc = dt.Columns; dc.Add("name", typeof(String)); dc.Add("version", typeof(String)); dc.Add("company", typeof(String)); dc.Add("description", typeof(String)); DirectoryInfo di = new DirectoryInfo(Application.StartupPath); FileInfo[] fi = di.GetFiles(); foreach (FileInfo f in fi) { if (f.Name.CompareTo("Mainsoft_Skin.dll") == 0) { AddRow(f.FullName, dt); } if (f.Name.CompareTo("kxebase.dll") == 0) { AddRow(f, dt); } } return dt; }

 

///

/// 添加内存表。 /// /// 获取的DLL。 /// 数据源。 private void AddRow(FileInfo f, DataTable dt) { FileVersionInfo fv = FileVersionInfo.GetVersionInfo(f.DirectoryName + "//" + f.Name); DataRow dr = dt.NewRow(); dr["name"] = f.Name; dr["version"] = fv.FileVersion; dr["company"] = fv.CompanyName; dr["description"] = fv.LegalCopyright; dt.Rows.Add(dr); }

 

显示:  gridControl1.DataSource = GetDLLtoDatatable().DefaultView;

 

 

你可能感兴趣的:(FileVersionInfo类显示dll信息)