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"] + "/Accounting/") + 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.AddAccoutingRequest(consultationrequestclass); int a = ConnectionClass.RetrieveLastId("RqstAccounting"); ConnectionClass.UpdateAccountingFilenamebyId(a); string oldname = Server.MapPath("~/Files/" + Session["login"] + "/Accounting/") + FileUpload1.PostedFile.FileName; string newname = Server.MapPath("~/Files/" + Session["login"] + "/Accounting/") + Convert.ToString(a) + ".pdf"; File.Move(oldname, newname); lblResult.Text = result; Label1.Visible = false; } } else { lblResult.Text = ""; } } }