Skip to content

Instantly share code, notes, and snippets.

@sohaiby
Created January 28, 2017 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sohaiby/1923e120b5a12f4a62bd4c04a200c5cb to your computer and use it in GitHub Desktop.
Save sohaiby/1923e120b5a12f4a62bd4c04a200c5cb to your computer and use it in GitHub Desktop.
HTML Multiple file upload
private object uploadFile(string filename)
{
//I've multiple fileupload controls in my form, that's why I am passing the name property of my fileupload control here
if (Request.Files.Count > 0)
{
HttpFileCollection files = Request.Files;
string[] keys = files.AllKeys; //Extracting the name of all files (which actually is the name of html file control) in order to identify the correct file w.r.t control
for (int i = 0; i < files.Count; i++)
{
if (keys[i] == filename && files[i].ContentLength > 0)
{
HttpPostedFile file = files[i];
string fname = Path.GetFileName(file.FileName);
file.SaveAs(Server.MapPath(Path.Combine("~/App_Data/", fname)));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment