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
for (int i = 0; i < Request.Files.Count; i++)
{
HttpPostedFileBase file = Request.Files[i];
}
instead of the foreach loop which was taking the same file twice
According to this site,
When multiple files are uploaded from a single file control, they are assigned the same name.
change this:
<input id="file-3" name="files" type="file" multiple>
to this:
<input id="files" name="files" type="file" multiple="multiple"/>
or:
<input id="files" name="files" type="file" multiple="true"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With