G
Guest
I need to pass a UNC path to the code and return the Free space on that drive, Can any one please pass through some samples that will assist.
Thanks ( C# Newbee )
Thanks ( C# Newbee )
drive, Can any one please pass through some samples that will assist.Glenn Wilson said:I need to pass a UNC path to the code and return the Free space on that
Shakir Hussain said:Try this
string myUNCPath = @"\\sys12345"
ConnectionOptions opt = new ConnectionOptions();
ObjectQuery oQuery = new ObjectQuery("SELECT FreeSpace FROM
Win32_LogicalDisk WHERE DriveType = 3");
ManagementScope scope = new ManagementScopemyUNCPath , opt);
ManagementObjectSearcher moSearcher = new
ManagementObjectSearcher(scope,
oQuery);
ManagementObjectCollection collection = moSearcher.Get();
foreach(ManagementObject res in collection)
{
decimal freeSpace =
Convert.ToDecimal(res["FreeSpace"])/1024/1024/1024;
MessageBox.Show ("Free Space (GB)- "+ freeSpace.ToString());
break;
}
--
Shak
(Houston)
drive, Can any one please pass through some samples that will assist.Glenn Wilson said:I need to pass a UNC path to the code and return the Free space on thatThanks ( C# Newbee )
Willy Denoyette said:Using System.Management and WMI, try this...
using System;
using System.Management;
class Tester {
public static void Main() {
GetFreeSpace(@"\\\\servername\\sharename"); // UNC path, Note the double
quotes!!!
}
public static void GetFreeSpace(string ProviderName )
{
String strSQL = "SELECT FreeSpace, QuotasDisabled ,VolumeName FROM
Win32_LogicalDisk WHERE providername='" + ProviderName + "'" ;
SelectQuery query = new SelectQuery(strSQL);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject mo in searcher.Get()) {
// Free disk space is irrelevant if per user quota's are enabled!
if(mo["QuotasDisabled"].ToString() != "true")
Console.WriteLine("{0} - Free bytes: {1} ",mo["VolumeName"],
mo["Freespace"]);
else
Console.WriteLine("{0} - Free bytes: {1} per-user quota's
applied!!",mo["VolumeName"], mo["Freespace"]);
}
}
}
Willy.
Glenn Wilson said:I need to pass a UNC path to the code and return the Free space on that
drive, Can any one please pass through some samples that will assist.
Thanks ( C# Newbee )
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.