jithesh
jithesh

Reputation: 253

How to list the local drives in dropdown?

In my project the dropdown should list all drives in local computer.

Here is the code: -

ddlDrives.Items.Clear();
ddlDrives.Items.Add("-Select-");
foreach (string objDrive in Directory.GetLogicalDrives())
{
     ddlDrives.Items.Add(objDrive);
}

But if It hosted in server ,Its showing server drives.I just want to show the User' Local system drives. What Should I do?

Upvotes: 0

Views: 791

Answers (1)

Rahul Singh
Rahul Singh

Reputation: 21815

You can use GetDrives method of DriveInfo Class:-

Try this:-

           if (!IsPostBack)
            {
                ddlDrives.Items.Clear();
                ddlDrives.Items.Add("-Select-");
                foreach (var d in DriveInfo.GetDrives())
                {
                    ddlDrives.Items.Add(d.Name);
                }
            }

Upvotes: 1

Related Questions