Request.Files same file downloaded by asp.net mvc

            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 times.

I use this control: https://github.com/kartik-v/bootstrap-fileinput

My cs.html

http://codepen.io/anon/pen/aekqm

Please find above my complete code.

+4
source share
3 answers

Solved my problem:

The code below is used.

for (int i = 0; i < Request.Files.Count; i++)
{
    HttpPostedFileBase file = Request.Files[i];
}

instead of a foreach loop that took the same file twice

+6
source

change this:

<input id="file-3" name="files" type="file" multiple>

:

<input id="files" name="files" type="file" multiple="multiple"/>

or

<input id="files" name="files" type="file" multiple="true"/>
+1
source

,

, .

+1

Source: https://habr.com/ru/post/1541952/


All Articles