Obtain Absolute Path RRS feed

  • Question

  • Hi

    I want to obtain the absolute path form a relative path




    Relative Path:"G:\Alejandro Gomez\setup.exe"


    Absolute Path:"\\psmnt03\General\Alejandro Gomez\setup.exe"


    when :


    psmnt03: is the server name.

    General: is a folder in this server.


    With the io.path.GetFullPath i can´t obtain that absolute folder.


    Could anybody tell me a way to make this conversion.


    Thank´s in advance.

    Thursday, May 24, 2007 2:17 PM


All replies

  • I think you are confusing your terminology here. The path "G:\..." which you have labelled "Relative Path" is actually an absolute path (or rooted path) as it begins with the drive. The path \\psmnt03\... which you have labelled "Absolute Path" is actually a UNC share path.


    There is no way to directly obtain a UNC share path from an absolute path, as any given absolute path could be shared as any number of UNC paths. The only way I can think of is to enumerate the shares on the computer using WMI (System.Management) and then check whether the directory in the absolute path is a subdirectory of the absolute path for each share.

    Thursday, May 24, 2007 5:23 PM
  • You'll need to P/Invoke the WNetGetConnection() API function.  Check this thread for code.
    Thursday, May 24, 2007 8:18 PM
  • That works, thanks for your help.
    Friday, May 25, 2007 1:22 PM