Multiple File Upload MVC C#

Uploading Multiple Files with MVC C#

Using HttpPostedFileBase[] files
upload is very easy.

Now Show you step by step.

Step 1
add Upload form in .chhtml file

@using (Html.BeginForm("Upload", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <label for="file">Upload Image:</label>
    <input type="file" name="files" value="" multiple="multiple"/>
    <input type="submit" value="Upload Image" />
}

Step 2
Now Add Action In Controller.

[HttpPost]
public ActionResult Upload(HttpPostedFileBase[] files)
{
    foreach (HttpPostedFileBase file in files)
    {
        string path = System.IO.Path.Combine(Server.MapPath("~/App_Data"), System.IO.Path.GetFileName(file.FileName));
        file.SaveAs(path);
    }
    ViewBag.Message = "File(s) uploaded successfully";
    return RedirectToAction("Index");
}

Full Demo Download.

Multiple File Upload MVC C# Multiple File Upload MVC C# Reviewed by Bhaumik Patel on 9:55 PM Rating: 5