protected void btnAdd_Click(object sender, EventArgs e) { DocumentDetails docObj = new DocumentDetails(); ELibraryDocumentBL docBLObj = new ELibraryDocumentBL(); try { string folderPath = Server.MapPath("~/Files/"); if (!Directory.Exists(folderPath)) { //If Directory (Folder) does not exists. Create it. Directory.CreateDirectory(folderPath); } string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName); if (fileName == "") { throw new ELibraryException("Select File"); } FileUpload1.SaveAs(folderPath + Path.GetFileName(FileUpload1.FileName)); docObj.DocumentPath = folderPath + Path.GetFileName(FileUpload1.FileName); docObj.DocumentName = txtDocumentName.Text; docObj.DocumentDescription = txtDescription.Text; if (cboDocumentType.SelectedIndex == -1) { throw new ELibraryException("Invalid Document Type"); } docObj.DocumentTypeID = docBLObj.GetDocumentTypeIDBL(cboDocumentType.SelectedItem.ToString()); if (cboDiscipline.SelectedIndex == -1) { throw new ELibraryException("Invalid Discipline"); } docObj.DisciplineID = docBLObj.GetDisciplineIDBL(cboDiscipline.SelectedItem.ToString()); docObj.Title = txtTitle.Text; docObj.Author = txtAuthor.Text; double price; bool isValidPrice = double.TryParse(txtPrice.Text, out price); if (!isValidPrice) { throw new ELibraryException("Invalid price"); } docObj.Price = price; docObj.UploadDate = DateTime.Today; if (docBLObj.AddNewDocumentBL(docObj)) { lblDisplay.Text = "Added"; //.Show("Added"); } else { lblDisplay.Text = "Failed"; } InitializeCombo(); } catch (ELibraryException ex) { lblDisplay.Text = ex.Message; } }