C# 从输入文件ASP.Net获取路径目录

C# 从输入文件ASP.Net获取路径目录,c#,asp.net-mvc,C#,Asp.net Mvc,我读了关于如何获取文件输入以选择目录的内容,链接到这里 现在的问题是获取它从目录中拾取的文件列表: 或 当用户单击submit按钮时,获取ASP.Net后端的目录路径 守则: // POST: /Gallery/CreateImage [HttpPost] public ActionResult CreateImage(FormCollection collection, HttpPostedFileBase file) { try { //For each

我读了关于如何获取文件输入以选择目录的内容,链接到这里

现在的问题是获取它从目录中拾取的文件列表:

当用户单击submit按钮时,获取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>

@使用(Html.BeginForm(“CreateFolder”、“Gallery”、FormMethod.Post、new{enctype=“multipart/formdata”}))
{
请确保文件夹结构采用以下格式:

  • 根文件夹
  • -艺术类别文件夹
  • --项目文件夹
  • ---图像
  • 请选择根文件夹
    提交 }
    正如user3559349在评论中指出的那样

    我将CreateImage方法更改为
    ActionResult CreateImage(IEnumerable folderUpload)


    我能够上传所有图像。

    您无法获取文件的完整路径(出于安全原因)早期版本的IE确实包含该文件,但现在已被删除)是否有方法获取文件?您是发布单个文件还是多个文件?您是如何在视图中生成文件输入的(名称属性是什么)。您需要显示相关的代码(以及为什么您使用
    FormCollection
    而不是您的模型)我还添加了HTML代码您有一个名为
    folderUpload
    的多文件输入,因此您的POST方法需要是
    public ActionResult CreateImage(IEnumerable folderUpload)
    -然后您可以循环浏览集合中的每个文件。而且不确定您是否只是省略了一些视图,但没有为
    标题
    ,`description'等发布任何内容