Created
January 28, 2017 05:18
-
-
Save sohaiby/1923e120b5a12f4a62bd4c04a200c5cb to your computer and use it in GitHub Desktop.
HTML Multiple file upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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