Search code examples
c#winapimicrosoft-distributed-file-system

Get DFS folder target (local server path) from a DFS path in C#


I have a DFS folder path...

\\domain.name\SharesRoot\DFSShare

I need to get the actual folder target of this root link or in other words the local server path that DFSShare is targetting

The local server path/folder target is as follows

\\MyServer\Share\MyShare

I've successfully used the NetDfsGetClientInfo() method to retrieve SOME of the needed information from the given DFS path

The DFS_STORAGE_INFO object that this method populates gives me the following data

  • State: irrelevant data
  • ServerName: 'MyServer'
  • ShareName: 'SharesRoot'

While the ServerName is what I'm looking for, the ShareName does not help me at all.

I need to find out what the path is on MyServer that the DFS path \\domain.name\SharesRoot\DFSShare is targetting

NetDfsGetInfo() gives me 1168 error, so that method is not helping, and I'm yet to try NetDfsEnum(), however my hopes aren't high seeing as it populates the same structs as the NetDfsGetClientInfo()... if anyone has any other leads here I'd be incredibly grateful!


Solution

  • So it seems the NetDfsGetClientInfo() is indeed the answer for my particular needs.

    The issue is that its behavior changes based on whether it's called on a DFS client machine versus if it's called on the DFS server machine.

    On a client machine the call returns a DFS_STORAGE_INFO object with the following data:

    • ServerName: 'MyServer'
    • ShareName: 'Share'

    All that's needed once this is returned is to append the subpath, which can be stripped out using the entry path of the DFS_INFO_3 object and the original path used in the NetDfsGetClientInfo() call