HTTP Posted File Helper V.1.0.2 Nugget Link
This is a light weight library that helps in the posting of files to IIS Web Server by providing a helper class FileHElper.cs which contains overloaded method ProcessFile() and ProcessFIleAsync() that reduces the boilerplate in posting files.
Installing..
Type the command below in Visual Studio Nuget Package Manager Console to install the library.
- PM> Install-Package HttpPostedFileHelper
Usage
Processing Single Files (Basic Usage)
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult UploadFile(HttpPostedFileBase file) {
- //Instanciate the Filehelper class to create a Filehelper Object
- FileHelper filehelper = new FileHelper();
- filehelper.ProcessFile(file, "/MyTargetLocation");
- return view();
- }
Processing Multiple Files
This makes a provision for multiple files being uploaded to the Server with an overridden method for processing an IEnumerable of files (HttpPostedFileBase Collection).
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult UploadFile(Model model, IEnumerable < HttpPostedFileBase > file) {
- FileHelper filehelper = new FileHelper();
- // ProcessFile returns count of files processed
- int postedfiles = filehelper.ProcessFile(file, "/MyTargetLocation");
- if (postedfiles > 0) {
- //files were written successfully
- }
- return View("Home");
- }

Join the conversation! Your thoughts help the community grow.