Created
June 12, 2014 22:32
-
-
Save menacestudio/6e4ff29cea8aea873e1c to your computer and use it in GitHub Desktop.
File upload
This file contains hidden or 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
HttpFileCollection uploadFiles = Request.Files; | |
// Build HTML listing the files received. | |
string summary = "<p>Files Uploaded:</p><ol>"; | |
// Loop over the uploaded files and save to disk. | |
int i; | |
for (i = 0; i < uploadFiles.Count; i++) | |
{ | |
HttpPostedFile postedFile = uploadFiles[i]; | |
// Access the uploaded file's content in-memory: | |
System.IO.Stream inStream = postedFile.InputStream; | |
byte[] fileData = new byte[postedFile.ContentLength]; | |
inStream.Read(fileData, 0, postedFile.ContentLength); | |
// Save the posted file in our "data" virtual directory. | |
postedFile.SaveAs(Server.MapPath("data") + "\\" + postedFile.FileName); | |
// Also, get the file size and filename (as specified in | |
// the HTML form) for each file: | |
summary += "<li>" + postedFile.FileName + ": " | |
+ postedFile.ContentLength.ToString() + " bytes</li>"; | |
} | |
summary += "</ol>"; | |
// If there are any form variables, get them here: | |
summary += "<p>Form Variables:</p><ol>"; | |
//Load Form variables into NameValueCollection variable. | |
NameValueCollection coll = Request.Form; | |
// Get names of all forms into a string array. | |
String[] arr1 = coll.AllKeys; | |
for (i = 0; i < arr1.Length; i++) | |
{ | |
summary += "<li>" + arr1[i] + "</li>"; | |
} | |
summary += "</ol>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment