I have two FileUpload on a single Web Page. The problem is that when I uploaded the file using FileUpload3 on specific folder it also upload the FileUpload2 file also on that folder. I want that when i click on Submit Button FileUpload3 upload file on specfic folder of only FileUpload3 not FileUpload2. I am using ASP.Net and C#.
My ASPX Code :
<asp:FileUpload ID="FileUpload2" runat="server" /></br>
<asp:FileUpload ID="FileUpload3" runat="server" AllowMultiple="true" />
and My C# Code :
if (FileUpload2.HasFile)
{
string time1 = INDIAN_ZONE.ToString("MM-dd-yyyy_hhmmss");
string directoryPath = Server.MapPath(string.Format("./Upload_Files/Day_Description/Destination_Image/" + DropDownList8.SelectedItem.Text + "/" + Label23.Text));
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
else
{
}
string fileName = Path.GetFileName(FileUpload2.PostedFile.FileName);
fileName = time1 + fileName;
string path = "./Upload_Files/Day_Description/Destination_Image/" + DropDownList8.SelectedItem.Text + "/" + Label23.Text + "/";
FileUpload2.PostedFile.SaveAs(Server.MapPath(path) + fileName);
}
else
{
string time1 = INDIAN_ZONE.ToString("MM-dd-yyyy_hhmmss");
string directoryPath = Server.MapPath(string.Format("./Upload_files/Day_Description/" + DropDownList8.SelectedItem.Text + "/" + Label23.Text));
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
else
{
}
}
if (FileUpload3.HasFile)
{
HttpFileCollection hfc = Request.Files;
for (int i = 0; i < hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i];
if (hpf.ContentLength > 0)
{
string FileExtention = System.IO.Path.GetExtension(FileUpload3.FileName);
string time1 = INDIAN_ZONE.ToString("MM-dd-yyyy_hhmmss");
string directoryPath = Server.MapPath(string.Format("./Upload_Files/Day_Description/Hotel_Image/" + DropDownList8.SelectedItem.Text + "/" + Label23.Text));
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
else
{
}
string fileName = Path.GetFileName(hpf.FileName);
fileName = time1 + fileName;
string path = "./Upload_Files/Day_Description/Hotel_Image/" + DropDownList8.SelectedItem.Text + "/" + Label23.Text + "/";
hpf.SaveAs(Server.MapPath(path) + fileName);
}
}
}
else
{
string time1 = INDIAN_ZONE.ToString("MM-dd-yyyy_hhmmss");
string directoryPath = Server.MapPath(string.Format("./Upload_Files/Day_Description/Hotel_Image/" + DropDownList8.SelectedItem.Text));
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
else
{
}
}
The problem is that when I uploaded the file using FileUpload3 on specific folder it also upload the FileUpload2 file also on that folder. I want that when i click on Submit Button FileUpload3 upload file on specfic folder of only FileUpload3 not FileUpload2. I am using ASP.Net and C#.