Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to get disk free space of shared network path in network server?
C#
private static void FreeSpaceNetwork(string srvname)
{
    try
    {
        ConnectionOptions conn = new ConnectionOptions();
        string strNameSpace = @"\\";
        if (srvname != "")
            strNameSpace += srvname;
        else
            strNameSpace += ".";
        strNameSpace += @"\dbbackup\WPS Archive ADIB\IntialDataBaseBackUpLocation\";
        System.Management.ManagementScope managementScope = new System.Management.ManagementScope(strNameSpace, conn);
        System.Management.ObjectQuery query = new System.Management.ObjectQuery("select * from Win32_LogicalDisk where DriveType=3");
        ManagementObjectSearcher moSearcher = new ManagementObjectSearcher(managementScope, query);
        ManagementObjectCollection moCollection = moSearcher.Get();
        foreach (ManagementObject oReturn in moCollection)
        {
            //foreach (PropertyData prop in oReturn.Properties)
            //{
            //    Console.WriteLine(prop.Name + " " + prop.Value);
            //}

            Console.WriteLine("Drive {0}", oReturn["Name"].ToString());
            Console.WriteLine("  Volume label: {0}", oReturn["VolumeName"].ToString());
            Console.WriteLine("  File system: {0}", oReturn["FileSystem"].ToString());
            Console.WriteLine("  Available space to current user:{0, 15} bytes", oReturn["FreeSpace"].ToString());
            Console.WriteLine("  Total size of drive:            {0, 15} bytes ", oReturn["Size"].ToString());
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
}

I tried the above code. But I am gettting Invalid Parameter Issue.
Posted
Updated 3-Jul-14 4:28am
v2
Comments
CHill60 3-Jul-14 10:28am    
And which line throws the invalid parameter exception?
Ravi Bhavnani 3-Jul-14 10:33am    
Seems like a common question today. See http://www.codeproject.com/Answers/792826/How-to-get-the-free-disk-space-of-a-remote-machine.

/ravi
CHill60 3-Jul-14 10:43am    
Ah ... homework then!!
Ravi Bhavnani 3-Jul-14 12:21pm    
Not sure 'bout that. (It seems too techy for homework). Methinks it's just a coincidence.

/ravi

1 solution

Your path looks to be invalid
C#
strNameSpace += @"\dbbackup\WPS Archive ADIB\IntialDataBaseBackUpLocation\";

Lose that last "\"
 
Share this answer
 
Comments
Member 10488324 3-Jul-14 10:54am    
Getting error on the code System.Management.ManagementScope managementScope = new System.Management.ManagementScope(strNameSpace, conn);
CHill60 3-Jul-14 12:25pm    
Yes ... I think because strNameSpace has a "\" at the end of it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900