我读到了如何获取文件输入以选择目录,请在此处链接how to get folder directory from html input type file or any other way
现在我遇到的问题是从目录中获取文件列表: folder count
OR
当用户点击提交按钮时,在ASP.Net的后端获取目录路径。
代码:
// POST: /Gallery/CreateImage
[HttpPost]
public ActionResult CreateImage(FormCollection collection, HttpPostedFileBase file)
{
try
{
//For each file in folder do the following
string title = collection["title"];
string description = collection["description"];
bool isSlide = collection["isSlider"] == "on" ? true : false;
bool isGallery = collection["isGallery"] == "on" ? true : false;
gallery = new Gallary(title, description, Path.GetExtension(file.FileName).Replace(".",string.Empty), isSlide, isGallery, Category.Drawing);
gallery.AddToGallery(gallery, file);
return View("GalleryManage", "Gallery");
}
catch
{
return View("GalleryManage", "Gallery");
}
}
HTML代码:
<div class="form-horizontal">
@using (Html.BeginForm("CreateFolder", "Gallery", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div class="box-body">
<div class="form-group">
<p>Please make sure that your folder structure is in the following format:</p>
<ol>
<li>Root Folder</li>
<li>-Art Category Folder</li>
<li>--Project Folder</li>
<li>---Images</li>
</ol>
</div>
<div class="form-group">
<label for="file">Please choose root folder</label>
<input type="file" name="folderUpload" webkitdirectory directory multiple />
</div>
<br />
<div class="box-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
}
</div>
答案 0 :(得分:0)
user3559349在评论中指出。
我将CreateImage方法发布更改为ActionResult CreateImage(IEnumerable<HttpPostedFileBase> folderUpload)
。
我能够上传所有图像。