Hello friends I am trying to save a file inside a folder that I create dynamically, up to here there is no problem, the point is that when I try to pass the file already in my method I receive it Like Null , could someone tell me where I'm missing? I'm getting this error.
[HttpPost]
public void CreateFolder() {
if (Request.Files.Count > 0)
{
foreach (HttpPostedFile file in Request.Files)
{
Random rnd = new Random();
int rndx = rnd.Next(0, 1000);
string extension = System.IO.Path.GetExtension(file.FileName);
string fname = System.IO.Path.GetFileName(file.FileName);
string dt = DateTime.Now.ToString("M/d/yyyy");
var folder = Server.MapPath("~/Facturas/" + rndx);
if (!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
string filePath = Path.Combine(Server.MapPath("~/Facturas/" + rndx)
, "" + rndx + "_" + dt + "_" + fname + "_" + extension);
file.SaveAs(filePath);
}
}
}
//end method
}
@using (Html.BeginForm("CreateFolder", "SAMAcceso", FormMethod.Post)) { @Html.TextBox("file","",new {type= "file" })
<input type="submit" value="cargar" /> }