Reputation: 437
I am using asp.net 3.5 version. In a single page I have 5 asp:FileUpload controls.
I have tried using the following code:
string path = Server.MapPath("~/MyFiles/");
string filename = "";
string extension = "";
int fcount = 1;
HttpFileCollection HFC = Request.Files;
for (int c = 0; c < HFC.Count; c++)
{
HttpPostedFile HPF = HFC[c];
if (HPF.ContentLength < 2100000) //2,100,000 bytes (approximately 2 MB)
{
extension = System.IO.Path.GetExtension(HPF.FileName);
filename = "ML" + MyId + fcount + extension;
HPF.SaveAs(path + "\\" + filename);
}
fcount++;
DBimg = filename + ",";
}
As it has 5 different upload control I am not getting the values for a single control. I need to save files that has been selected separately from those upload controls into separate folders. From HPF how can I get different controls.Is there any way out??
P.N. - In asp.net 3.5 file upload controls for multiple selection doesn't provide MyUploader1.PostedFiles instead it provide MyUploader1.PostedFile
Please help me out...Any advice is welcome.
Upvotes: 0
Views: 1270
Reputation: 510
If you're looking to upload multiple files from a single file upload control then set the FileUpload.AllowMultiple property to true (this only works in .NET 4.5). This is discussed further in this question: How to choose multiple files using File Upload Control?
If you're looking at uploading multiple files from multiple file upload controls on a single page, then you will need to extract the file from each individual uploader. For example:
if(firstUploader.HasFile)
{
HttpPostedFile firstFile = firstUploader.PostedFile;
firstFile.SaveAs(Server.MapPath("~/MyFiles/FirstUploaderContent/" + firstFile.FileName);
}
if(secondUploader.HasFile)
{
HttpPostedFile secondFile = secondUploader.PostedFile;
secondFile.SaveAs(Server.MapPath("~/MyFiles/SecondUploaderContent/" + secondFile.FileName);
}
// Handle further files here ...
Upvotes: 1