Friday, March 20, 2009

Multiple File uploading using C#.Net?

HttpFileCollection uploadFilCol = Request.Files;
for(int i=0;i<uploadFilCol.Count;i++)
{
HttpPostedFile file = uploadFilCol[i];
string fileExt = Path.GetExtension(file.FileName).ToLower();
string fileName = Path.GetFileName(file.FileName);
if(fileName != string.Empty)
{
try
{
if(fileExt == ".jpg" || fileExt == ".gif")
{
file.SaveAs(Server.MapPath("./Images/") + fileName);
this.ShowMessage(" " + fileName + " Successfully Uploaded",i);
}
else
{
file.SaveAs(Server.MapPath("./Others/") + fileName);
this.ShowMessage(" " + fileName + " Successfully Uploaded",i);
}
}
catch(Exception ex)
{
this.ShowMessage(" " + ex.Message, i);
}
}
}

No comments:

 
Feedback Form