Monday, March 5, 2012

how to upload multiple files in asp.net

Here i will show how to upload multiple file using File upload control in asp.net.For this i have taken one HttpFileCollection to upload the multiple files.

CodeBehind:
protected void btnUpload_Click(object sender, EventArgs e)
{ 
if (FileUpload.HasFile)
{ 
// Get the HttpFileCollection
HttpFileCollection uploadeFiles = Request.Files;
for (int i = 0; i < uploaded.Count; i++) { HttpPostedFile Hpostfiles = uploadedFiles[i]; if (Hpostfiles.ContentLength > 0)
{
Hpostfiles.SaveAs(Server.MapPath("~/Upload/Test/") + Path.GetFileName(Hpostfiles.FileName));
}
} 
}
}
Post a Comment

Bel