Implementing multiple file uploads in ASP.NET
Author:Eve Cole
Update Time:2009-06-30 15:33:11
private Boolean SaveFiles()
{
//Get the File form element
HttpFileCollection files = HttpContext.Current.Request.Files;
try
{
for(int intCount= 0; intCount< files.Count; intCount++)
{
HttpPostedFile postedFile = files[intCount];
string fileName, fileExtension;
//Get file name
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName != "")
{
//Get file name extension
fileExtension = System.IO.Path.GetExtension(fileName);
//Can save files to different folders according to different extension names
//Note: You may need to modify the anonymous write permissions of your folder.
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("upFiles/") + fileName);
}
}
return true;
}
catch(System.ExceptionEx)
{
return false;
}
}