Determine machine name of a server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sternchen
    New Member
    • Oct 2007
    • 4

    Determine machine name of a server

    Hello,

    I have a .NET application through which a user can select files. This happens through the OpenFileDialog. Now, I also need to know whether that file is on my local machine or from a server. How can I find out the exact machine name from where the file is loaded, so that i can compare that with my local machine name later?

    cheers,
    sternchen
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    What ?

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      The machine name for the machine running your code can be gained with Environment.Mac hineName

      Other then that I don't know what you are getting at?

      Comment

      • sternchen
        New Member
        • Oct 2007
        • 4

        #4
        Ok :), thanks for your quick reply. I think an example helps.

        The user selects a file on a server and the UNC path will look like

        \\pc1234\folder \file.txt

        First, I thought that I could just look for the first part which would give me the string "pc1234" but I want to have a more general. So, is their any way to find out the computer name on which that particular file is located on?

        cheers

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          You might be able to get something from File.GetAccessC ontrol() but I'm not sure.

          Comment

          • sternchen
            New Member
            • Oct 2007
            • 4

            #6
            For everybody with the same problem.

            I found a great blog with the code which works perfectly. Check it out at
            http://www.saunalahti. fi/janij/blog/2007-01.html

            cheers,
            sternchen

            Comment

            Working...