I am using a byte[]
to get a serialized version of a file that I want to upload to my ASP.NET website. I am using HttpPostedFileBase
on your view model to hold the uploaded file
public class MyViewModel
{
[Required]
public HttpPostedFileBase File { get; set; }
}
My HomeController
is
public class HomeController: Controller
{
public ActionResult Index()
{
var model = new MyViewModel();
return View(model);
}
[HttpPost]
public ActionResult Index(MyViewModel model)
{
if (!ModelState.IsValid)
return View(model);
byte[] uploadedFile = new byte[model.File.InputStream.Length];
model.File.InputStream.Read(uploadedFile, 0, uploadedFile.Length);
// Where do I write the file to?
return Content("Upload complete");
}
}
and finally in my view I have
@model MyViewModel
@using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div>
@Html.LabelFor(x => x.File)
@Html.TextBoxFor(x => x.File, new { type = "file" })
@Html.ValidationMessageFor(x => x.File)
</div>
<button type="submit">Upload</button>
}
The uploads will only be performed by me (the Administrator), and there will only be two, both application installers (.exe files, one 8MB and the other 18MB). My question is how/where can I store the uploaded files so that users can download these?
Thanks for your time.