I have two separate asp:FileUpload controls under a single asp form like this:
https://i.stack.imgur.com/KJBU9.png
I have written two different functions to save two different files onto a local directory
protected void profileImageUpload()
{
if (profile_image_input.HasFile)
{
string imagePath = "/Images/" + Session["name"]+"_profile_image"+ System.IO.Path.GetExtension(profile_image_input.FileName);
profile_image_input.SaveAs(Server.MapPath(imagePath));
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "update uni_login set profile_image_path =" + "'" + imagePath + "'" + "where name =" + "'" + Session["name"] + "';";
cmd.ExecuteNonQuery();
con.Close();
Response.Redirect(Request.RawUrl);
}
}
protected void campusImageUpload()
{
if (campus_image_input.HasFile)
{
string imagePath = "/Images/" + Session["name"] + "_campus_image" + System.IO.Path.GetExtension(campus_image_input.FileName);
campus_image_input.SaveAs(Server.MapPath(imagePath));
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "update uni_login set campus_image_path =" + "'" + imagePath + "'" + "where name =" + "'" + Session["name"] + "';";
cmd.ExecuteNonQuery();
con.Close();
}
}
and when I click the "Update Profile" button as seen on the image above, both of the functions get called
protected void updateProfileClick(object sender, EventArgs e)
{
profileImageUpload();
campusImageUpload();
Response.Redirect(Request.RawUrl);
}
and onclick:
<asp:Button ID="update_profile_button" Text="Update Profile" OnClick="updateProfileClick" runat="server" CssClass="btn btn-primary"/>
but the problem here is that when the page is loaded and I try to upload two files, that is when i populate both the fileuploads with a file, only the file from first fileupload control gets saved to local directory but when i leave the first fileupload control blank and upload a file on the second fileupload control it gets saved. so the main problem here is that only one file from two of these fileuploads actually gets saved onto the local directory. This seems to be a unique problem I couldn't find solution to this anywhere so any help would be appreciated.