foreach (string fileName in Request.Files)
{
HttpPostedFileBase file = Request.Files[fileName];
//Save file content goes here
fName = file.FileName;
if (file != null && file.ContentLength > 0)
{
subPath = ConfigurationManager.AppSettings["SubPath"].ToString() + "/" + currentUserId;
bool isExists = System.IO.Directory.Exists(Server.MapPath(subPath));
if (!isExists)
System.IO.Directory.CreateDirectory(Server.MapPath(subPath));
string path = System.IO.Path.Combine(Server.MapPath(subPath), System.IO.Path.GetFileName(file.FileName));
file.SaveAs(path);
}
}
If i upload multiple files i get the same file n number of the times.
I am using this control: https://github.com/kartik-v/bootstrap-fileinput
My cs.html
http://codepen.io/anon/pen/aekqm
Please find above my complete code.
Solved my issue:
Used the code below
instead of the foreach loop which was taking the same file twice
According to this site,
change this:
to this:
or: