locked
Getting File Information Issue? RRS feed

  • Question

  • I read up a lot on this, and found a good example of doing this.  Basically, I want to take a look at a file and get the File Version.  When I run my code though, I am getting a LOT of data...  The File Version is in there, but I want to only get that...  So, I was wondering what I might be doing wrong...

    Here is my code:

    Code Snippet

    try
    {
    string localApp = Environment.CurrentDirectory + @"\WindowsApplication2.exe";
    string localZip = Environment.CurrentDirectory + @"\Ionic.Utils.Zip.dll";

    FileVersionInfo localAppVInfo = FileVersionInfo.GetVersionInfo(localApp);
    FileVersionInfo localZipVInfo = FileVersionInfo.GetVersionInfo(localZip);

    using (FileStream fs = new FileStream(Environment.CurrentDirectory + @"\Update.txt", FileMode.Create))
    {
    using (StreamWriter w = new StreamWriter(fs, Encoding.ASCII))
    {
    w.WriteLine("localAppVInfo " + localAppVInfo.ToString());
    w.WriteLine("localAppLocation " + localApp.ToString());
    w.WriteLine("localZipVInfo " + localZipVInfo.ToString());
    w.WriteLine("localZipLocation " + localZip.ToString());
    w.Write("");
    }
    }
    }
    catch
    {
    }



    When I save the text though I get all of this:

    Code Snippet

    localAppVInfo File: C:\Documents and Settings\********\My Documents\Visual Studio 2005\Projects\WindowsApplication2\WindowsApplication2\bin\Debug\WindowsApplication2.exe
    InternalName: WindowsApplication2.exe
    OriginalFilename: WindowsApplication2.exe
    FileVersion: 2.0.0.0
    FileDescription: WindowsApplication2
    Product: WindowsApplication2
    ProductVersion: 2.0.0.0
    Debug: False
    Patched: False
    PreRelease: False
    PrivateBuild: False
    SpecialBuild: False
    Language: Language Neutral

    localAppLocation C:\Documents and Settings\********\My Documents\Visual Studio
    2005\Projects\WindowsApplication2\WindowsApplication2\bin\Debug\WindowsApplication2.exe
    localZipVInfo File: C:\Documents and Settings\********\My Documents\Visual Studio 2005\Projects\WindowsApplication2\WindowsApplication2\bin\Debug\Ionic.Utils.Zip.dll
    InternalName: Ionic.Utils.Zip.dll
    OriginalFilename: Ionic.Utils.Zip.dll
    FileVersion: 1.5.0.5
    FileDescription: Ionic's Zip Library
    Product: ZipLibrary
    ProductVersion: 1.5.0.5
    Debug: False
    Patched: False
    PreRelease: False
    PrivateBuild: False
    SpecialBuild: False
    Language: Language Neutral

    localZipLocation C:\Documents and Settings\********\My Documents\Visual Studio 2005\Projects\WindowsApplication2\WindowsApplication2\bin\Debug\Ionic.Utils.Zip.dll



    Thanks Again,
    Monday, July 28, 2008 8:38 PM

Answers

  • Alright, 2 things:

    1) For some reason the code I posted now appears incomplete...  Not sure why...

    2) I found a solution for this.  Basically, the code "Gets" the File Version, but it does not set the string as containing it.  So...  This code works... (In case anyone else is trying to do this):

    Code Snippet

    try
    {
    //Agregate Local Data
    string localApp = Environment.CurrentDirectory + @"\WindowsApplication2.exe";
    string localZip = Environment.CurrentDirectory + @"\Ionic.Utils.Zip.dll";

    FileInfo localAppInfo = new FileInfo(localApp);
    FileInfo localZipInfo = new FileInfo(localZip);

    FileVersionInfo localAppVInfo = FileVersionInfo.GetVersionInfo(localApp);
    FileVersionInfo localZipVInfo = FileVersionInfo.GetVersionInfo(localZip);

    int localAppVInt = Convert.ToInt32(localAppVInfo.FileVersion);
    int localZipVInt = Convert.ToInt32(localZipVInfo.FileVersion);

    //Agregate Server Data
    string serverApp = @"\\*****\";
    string serverZip = @"\\*****\";

    FileInfo serverAppInfo = new FileInfo(serverApp);
    FileInfo serverZipInfo = new FileInfo(serverZip);

    FileVersionInfo serverAppVInfo = FileVersionInfo.GetVersionInfo(serverApp);
    FileVersionInfo serverZipVInfo = FileVersionInfo.GetVersionInfo(serverZip);

    int serverAppVInt = Convert.ToInt32(serverAppVInfo.FileVersion);
    int serverZipVInt = Convert.ToInt32(serverZipVInfo.FileVersion);

    //Generate Update.txt
    using (FileStream fs = new FileStream(Environment.CurrentDirectory + @"\Update.txt", FileMode.Create))
    {
    using (StreamWriter w = new StreamWriter(fs, Encoding.ASCII))
    {
    w.WriteLine("-------Local Data-------");
    w.WriteLine("localAppVInfo " + localAppVInfo.FileVersion.ToString());
    w.WriteLine("localAppLocation " + localApp.ToString());
    w.WriteLine("localZipVInfo " + localZipVInfo.FileVersion.ToString());
    w.WriteLine("localZipLocation " + localZip.ToString());
    w.WriteLine("");
    w.WriteLine("-------Server Data-------");
    w.WriteLine("serverAppVInfo " + serverAppVInfo.FileVersion.ToString());
    w.WriteLine("serverAppLocation " + serverApp.ToString());
    w.WriteLine("serverZipVInfo " + serverZipVInfo.FileVersion.ToString());
    w.WriteLine("serverZipLocation " + serverZip.ToString());
    w.Write("");
    }
    }


    I hope this helps someone else.

    Thanks Again,
    Monday, July 28, 2008 10:48 PM