How can I show the version and the company name of selected file

37 views Asked by At

I'm writing a project in C# which has a button to select a file (.elk) which is about Eplan, and show the path and the name of file in 2 text boxes.

Now I want to have a label that when I select my file with the button, show the details of the selected file like company name and version of the file - how can I do it?

string filePath = ofd.FileName;

// Check if the file exists
if (System.IO.File.Exists(filePath))
{
    try
    {
        // Get the file version information
        FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(filePath);

        // Retrieve the file version
        string fileVersion = versionInfo.FileVersion;

        // Set the Label text with the file version
        label1.Text = $"File Version: {fileVersion}";
    }
    catch (Exception ex)
    {
        label1.Text = "Error getting file version: " + ex.Message;
    }
}
else
{
    label1.Text = "File does not exist.";
}
0

There are 0 answers