Andrew,
It's not an oversight, it's the design of the class. A logical drive
and a network share are two separate things which sometimes are the same (if
that makes sense).
If you want to get this information in a consistent manner, then use the
GetDiskFreeSpace API call, or some other API which allows both logical
drives and UNC names.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"andrewcw" <an******@acw.com> wrote in message
news:E4**********************************@microsof t.com...
Thanks - I was trying to stay as much as possible within managed code.
While waiting I put this code together - although it is not as direct ...it
does get me the drive ltr & then I can use WMI for size. Seems an odd
oversight in the class to not have such a function...
public string getDrvLtrFromUNC(string UNCPath)
{ // get all the named drives then see whose ProviderName
// matches the UNCPath, then return that drive letter ( form of "e: " -
2 chars) // empty string would be an unmapped or invalid drive path.
string retVal="";
string thisDescrip="";
string thisUNCroot="";
string ltrDr="";
string wackyQuery="";
string [] logDrives=Directory.GetLogicalDrives();
for (int i = 0; i<logDrives.GetLength(0);i++)
{
ltrDr=logDrives[i].Substring(0,2);
wackyQuery =string.Format("Win32_LogicalDisk.DeviceID=\"{0}\" ",ltrDr);
ManagementObject moDrive =new ManagementObject(wackyQuery);
thisDescrip= moDrive.Properties["Description"].Value.ToString();
if (thisDescrip.IndexOf("Network")>-1)
{
thisUNCroot = moDrive.Properties["ProviderName"].Value.ToString();
if (thisUNCroot.ToLower().IndexOf(UNCPath.ToLower())>-1)
{
retVal = ltrDr;
break;
}
} // end of a network drive
} // end of for loop
return retVal;
}