locked
Getting File Info from a file on a network drive? RRS feed

  • Question

  • I have an application that get File Information (Version specifically).  I have this working perfectly with files on the local machine, but I want to also check files on the server.  When I try to do this the application stops...  I was wondering if I had to do something differently when trying to get the information from a file that is not actually on the machine the application is running on...?

    Here is the code I am using to get the information from the files on the server:

    Code Snippet

    string serverApp = @"\\HomeServer\shared\Apps\WindowsApplication2.exe";
    string serverZip = @"\\HomeServer\shared\Apps\Ionic.Utils.Zip.dll";

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

    FileVersionInfo serverAppVInfo = FileVersionInfo.GetVersionInfo(serverApp); //It hangs here.
    FileVersionInfo serverZipVInfo = FileVersionInfo.GetVersionInfo(serverZip); //And would hang here if the above line wasn't there...




    Thanks Again,
    Wednesday, July 30, 2008 8:48 PM

Answers

  • I've got no idea what I mean with thread-safe. 

     

    I was reading around the internet, found a good article about it and copy-pasted the link, but then made a typo etc, and before I know it I pressed ctrl-C again and gone was the link.  Now I can't find it anymore.  (And I auto-clear my IE history every 15 secs because I'm at work hehe)

     

    Anways, I remember that the only thing I could think of was that I did find some guys discussing the static methods of the FileInfo class, and how it didn't manage its streams correctly, in the case of MultiThreading AND reading multiple files.

    Maybe the FileInfo class, that basically reads the .exe header (or whatever) on a file, locks the file for exclusive acces but then something goes wrong somewhere and that's why it's hanging? Because it's waiting? Probably not, because it would throw an error, not hang...

     

    Can you start a new project, copy-paste only the lines of code above (so no thread/backgroundworker and read files one by one) and let me know if we're on to anything here?

     

    I'll start a couple of tests on our server here at work after my lunchbreak. 

    Thursday, July 31, 2008 10:28 AM
  • No such luck, I even made it messy by doing everything I asked you not to do (read sequential and threading).

    This gets the requested info from the files on one of our servers without anything noticable going wrong.

    class Program

    {

    static void Main(string[] args)

    {

    ThreadStart ts = new ThreadStart(GetInfo);

    Thread t = new Thread(ts);

    t.Start();

    Console.ReadKey();

    }

    static void GetInfo()

    {

    Thread.Sleep(5000);

    string file1Location = @"\\swbcb\SWIMMO\136.txt";

    string file2Location = @"\\swbcb\SWIMMO\logo.tps";

    FileInfo file1Info = new FileInfo(file1Location);

    FileInfo file2Info = new FileInfo(file2Location);

    FileVersionInfo file2Version = FileVersionInfo.GetVersionInfo(file2Location);

    FileVersionInfo file1Version = FileVersionInfo.GetVersionInfo(file1Location);

    Console.WriteLine("Completed");

    }

    }

     

    I'll be honest, I'm really sorry, but I don't think I can solve this. Sad Hopefully someone smarter comes along :-)

    Thursday, July 31, 2008 12:12 PM

All replies

  • I couldn't find anything on the net about your particular problem, nor duplicate your setup, don't have homeServer, but I'm thinking of two things...

     

    FileVersionInfo isn't really thread-safe, are you multi-threading here?

    Also, this is a really long shot, try to organise your code file per file, that way the server's harddisk doenst have to jump back and forwarth between locations to read:

     

    Code Snippet

    string serverApp = @"\\HomeServer\shared\Apps\WindowsApplication2.exe";
    FileInfo serverAppInfo = new FileInfo(serverApp);
    FileVersionInfo serverAppVInfo = FileVersionInfo.GetVersionInfo(serverApp);

     

    string serverZip = @"\\HomeServer\shared\Apps\Ionic.Utils.Zip.dll";
    FileInfo serverZipInfo = new FileInfo(serverZip);
    FileVersionInfo serverZipVInfo = FileVersionInfo.GetVersionInfo(serverZip);

     

     

    Thursday, July 31, 2008 8:23 AM
  • Thank you very much for your response.  I will try the second suggestion (Which is probably a good practice anyway I would think.  I really wrote that code poorly in retrospect.). 

    To answer your question though, I am using a backgroundWorker to perform this work (As otherwise it was locking up the UI a bit).  How do you mean "thread-safe"?  Can this not be done in a backgroundWorker thread?  The local files do work fine...  It's just the server files that are having a problem.

    Thanks Again,
    Thursday, July 31, 2008 8:52 AM
  • I've got no idea what I mean with thread-safe. 

     

    I was reading around the internet, found a good article about it and copy-pasted the link, but then made a typo etc, and before I know it I pressed ctrl-C again and gone was the link.  Now I can't find it anymore.  (And I auto-clear my IE history every 15 secs because I'm at work hehe)

     

    Anways, I remember that the only thing I could think of was that I did find some guys discussing the static methods of the FileInfo class, and how it didn't manage its streams correctly, in the case of MultiThreading AND reading multiple files.

    Maybe the FileInfo class, that basically reads the .exe header (or whatever) on a file, locks the file for exclusive acces but then something goes wrong somewhere and that's why it's hanging? Because it's waiting? Probably not, because it would throw an error, not hang...

     

    Can you start a new project, copy-paste only the lines of code above (so no thread/backgroundworker and read files one by one) and let me know if we're on to anything here?

     

    I'll start a couple of tests on our server here at work after my lunchbreak. 

    Thursday, July 31, 2008 10:28 AM
  • No such luck, I even made it messy by doing everything I asked you not to do (read sequential and threading).

    This gets the requested info from the files on one of our servers without anything noticable going wrong.

    class Program

    {

    static void Main(string[] args)

    {

    ThreadStart ts = new ThreadStart(GetInfo);

    Thread t = new Thread(ts);

    t.Start();

    Console.ReadKey();

    }

    static void GetInfo()

    {

    Thread.Sleep(5000);

    string file1Location = @"\\swbcb\SWIMMO\136.txt";

    string file2Location = @"\\swbcb\SWIMMO\logo.tps";

    FileInfo file1Info = new FileInfo(file1Location);

    FileInfo file2Info = new FileInfo(file2Location);

    FileVersionInfo file2Version = FileVersionInfo.GetVersionInfo(file2Location);

    FileVersionInfo file1Version = FileVersionInfo.GetVersionInfo(file1Location);

    Console.WriteLine("Completed");

    }

    }

     

    I'll be honest, I'm really sorry, but I don't think I can solve this. Sad Hopefully someone smarter comes along :-)

    Thursday, July 31, 2008 12:12 PM
  • Hello,

      There are not many cases where this should fails :

    -> permission denied on files

    -> file does not exists...

      I made quick check here and all working really nice...

      Do you have more details of "//It hangs here." : what is the exception.Message ?

      Regards,

          Stéphane

     

    Thursday, July 31, 2008 2:09 PM
  • I think that's the problem: it's not throwing an exeption, just hanging?

    Thursday, July 31, 2008 3:02 PM
  • oki looks strange but possible reasons should be a network issue...Try waiting long time (timeout max on network is something like 7 minutes I think but not sure). Maybe you will then have an exception...

    Small check : try to open the folder using explorer, maybe there is a security issue on the share (firewall active, dns resolution fails, ...)

    Hope this helps,

        Stéphane

    Thursday, July 31, 2008 3:26 PM
  •  MLyons10 wrote:
    I have an application that get File Information (Version specifically).  I have this working perfectly with files on the local machine, but I want to also check files on the server.  When I try to do this the application stops...  I was wondering if I had to do something differently when trying to get the information from a file that is not actually on the machine the application is running on...?


    I have to agree with DarkAngel_FR, this sounds more like a network issue (firewall perhaps?), or a permissions issue. 

    At my last job, I wrote an app that updated files on a user's computer by comparing the version and/or date with the copy on the server.  The code was the exact same for a local file as the server file, the only thing changed was the path that was passed in.

    Try a simple File.Exists() on one of the files to see if it can even be reached.

    if (File.Exists(@"\\HomeServer\shared\Apps\WindowsApplication2.exe"))

         MessageBox.Show("File exists!");
    else
        MessageBox.Show("File could not be found.");
    Friday, August 1, 2008 1:58 PM