koss koss - 27 days ago 21
C# Question

Populate datagridview with FileVersionInfo

I would need to fill a datagrid with the values of versioninfo prellevato by a double foreach.


incorro error:
FileVersionInfo.GetVersionInfo (file)
; (incorrect syntax)


DirectoryInfo dir = new DirectoryInfo(@"D:\TEMP\");

foreach (DirectoryInfo folder in dir.GetDirectories())
{
foreach (FileInfo file in folder.GetFiles())
{
FileVersionInfo verInfo = FileVersionInfo.GetVersionInfo(file);
dataGridView1.ColumnCount = 1;
dataGridView1.Columns[0].Name = "Version";
string[] row = new string[] { verInfo.ProductVersion };
dataGridView1.Rows.Add(row);
}
}

Answer

As BugFinder already pointed you to the documentation of the method FileVersionInfo.GetVersionInfo

It takes only a string as parameter. So you should give it the filename and not the FileInfo

FileVersionInfo verInfo = FileVersionInfo.GetVersionInfo(file.FullName);