我正在尝试从网络上共享的公共驱动器中获取文件夹的所有名称。我知道这很简单,但是我认为服务器路径是错误的,我尝试对路径使用各种变体,但它不起作用。
我的控制器
public ActionResult GetFolders()
{
string path = Server.MapPath("\\\\NC2PWSHV1\\Users");
List<string> picFolders = new List<string>();
foreach (string dir in Directory.GetDirectories(path))
{
picFolders.Add(dir);
}
return View(picFolders);
}
我的看法
@model IEnumerable<string>
@{
ViewBag.Title = "GetFolders";
}
<h2>GetFolders</h2>
<table>
<tbody>
@foreach (string picFolders in Model)
{
<tr>
<td>
@picFolders
</td>
</tr>
}
</tbody>
</table>
有一篇MS文章将在这里满足您的需求:https : //docs.microsoft.com/zh-cn/dotnet/standard/io/how-to-enumerate-directories-and-files
您需要的主要内容是:
string dirPath = @"\\archives\2009\reports";
List<string> dirs = new List<string>(Directory.EnumerateDirectories(dirPath));
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句