public static String GetSharePath(String DFSPath) { if (!String.IsNullOrEmpty(DFSPath)) { IntPtr Buffer = IntPtr.Zero; try { int Error = NetDfsGetClientInfo(DFSPath, null, null, 3, out Buffer); if (Error == 0) { DFS_INFO_3 DFSInfo = (DFS_INFO_3)Marshal.PtrToStructure(Buffer, typeof(DFS_INFO_3)); if ((DFSInfo.State & DFS_VOLUME_STATE_OK) > 0) { String SubPath = DFSPath.Remove(0, 1 + DFSInfo.EntryPath.Length).TrimStart(new Char[] { '\\' }); for (int i = 0; i < DFSInfo.NumberOfStorages; i++) { IntPtr Storage = new IntPtr(DFSInfo.Storages.ToInt64() + i * Marshal.SizeOf(typeof(DFS_STORAGE_INFO))); DFS_STORAGE_INFO StorageInfo = (DFS_STORAGE_INFO)Marshal.PtrToStructure(Storage, typeof(DFS_STORAGE_INFO)); if ((StorageInfo.State & DFS_STORAGE_STATE_ACTIVE) > 0) { if (String.IsNullOrEmpty(SubPath)) { return(String.Format(@"\\{0}\{1}", StorageInfo.ServerName, StorageInfo.ShareName)); } else { return(GetSharePath(String.Format(@"\\{0}\{1}\{2}", StorageInfo.ServerName, StorageInfo.ShareName, SubPath))); } } } } } else if (Error == 2662) { return(DFSPath); } } finally { NetApiBufferFree(Buffer); } } return(null); }
public static string GetDfsInfo(string server) { string rval = null; IntPtr b; int r = NetDfsGetInfo(server, null, null, NetDfsInfoLevel.DfsInfo3, out b); if (r != 0) { NetApiBufferFree(b); // return passed string if not DFS return(rval); } DFS_INFO_3 sRes = GetStruct <DFS_INFO_3>(b); if (sRes.NumberOfStorages > 0) { DFS_STORAGE_INFO sResInfo = GetStruct <DFS_STORAGE_INFO>(sRes.Storage); rval = string.Concat(@"\\", sResInfo.ServerName, @"\", sResInfo.ShareName, @"\"); } NetApiBufferFree(b); return(rval); }