protected void btnSubmit_Click(object sender, EventArgs e) { if (FileUpload1.HasFile) { if (FileUpload1.PostedFile.ContentType.Equals("application/pdf")) { if (flag == true) { try { string filename = Path.GetFileName(FileUpload1.FileName); FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Files/" + Session["login"] + "/Business/") + filename); } catch (Exception ex) { lblFileUpload.Text = "File could not be uploaded" + ex.Message; } } } else { lblFileUpload.Text = "File must be a PDF File"; } if (lblFileUpload.Text == "") { if (flag == true) { string selectedDate = txtDeadline.Text; DateTime dt1 = DateTime.Parse(selectedDate); ConsultationRequestClass consultationrequestclass = new ConsultationRequestClass(txtName.Text, Session["login"].ToString(), txtMail.Text, txtTitle.Text, DropDownList1.SelectedItem.Text, dt1, txtDescription.Text, FileUpload1.PostedFile.FileName.ToString(), "Processing", ""); string result = ConnectionClass.AddBusinessRequest(consultationrequestclass); int a = ConnectionClass.RetrieveLastId("RqstBusiness"); ConnectionClass.UpdateBusinessFilenamebyId(a); string oldname = Server.MapPath("~/Files/" + Session["login"] + "/Business/") + FileUpload1.PostedFile.FileName; string newname = Server.MapPath("~/Files/" + Session["login"] + "/Business/") + Convert.ToString(a) + ".pdf"; File.Move(oldname, newname); lblResult.Text = result; Label1.Visible = false; } } else { lblResult.Text = ""; } } }