如何在C#MVC中选择文件夹目的地?

时间:2012-05-30 22:23:58

标签: c# asp.net-mvc model-view-controller path directory

我想知道如何在MVC中选择目标文件夹的目录,例如folderbrowserdialog?

喜欢这张图片http://www.codeguru.com/img/legacy/files/getFolder1.gif

例如,如果我选择一个文件夹,我想获取路径,如\ Server \ Folder1 \ Folder11

谢谢!

1 个答案:

答案 0 :(得分:0)

可能是这个吗?

有些聊天你可以在那里找到

http://www.eggheadcafe.com/community/csharp/2/10116970/accessing-shared-folder-on-a-network-using-c-code.aspx

代码段1:

List<string> mappedDrives = new List<string>();
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drvInfo in drives)
{
          if (drvInfo.DriveType == DriveType.Network)
            mappedDrives.Add(drvInfo.Name);
}

代码段2:

ManagementScope mgmtScope = new ManagementScope();
//query for drivetype = 4..for  network drive
ObjectQuery objQuery = new ObjectQuery("SELECT VolumeName FROM Win32_LogicalDisk   WHERE DriveType= 4");
ManagementObjectSearcher mgmgObjSearch = new ManagementObjectSearcher(mgmtScope,   objQuery);
ManagementObjectCollection mgmgObjColl = mgmgObjSearch.Get();
foreach (ManagementObject mgmgObj in mgmgObjColl)
{
    mappedDrives.Add(mgmgObj["VolumeName"].ToString());
}