- protected void btnSave_Click(object sender, EventArgs e) {
- bool locationChecked = false;
- try {
- DDS_Document doc = new DDS_Document();
-
- #
- region "Upload file to specific location in server"
- if (string.IsNullOrEmpty(fluDocument.FileName)) {
- ScriptManager.RegisterStartupScript(Page, this.GetType(), "alert", string.Format("alert('{0}');", "Please select file to Upload"), true);
- return;
- }
- if (fluDocument.HasFile) {
-
- string transferfile = "";
- transferfile = fluDocument.FileName;
-
- fluDocument.PostedFile.SaveAs(filePath + transferfile);
-
- } else {
- ScriptManager.RegisterStartupScript(Page, this.GetType(), "alert", string.Format("alert('{0}');", "File Could not be Updated"), true);
- return;
- }#
- endregion
- if (!string.IsNullOrEmpty(fluDocument.FileName)) {
- tokens = fluDocument.PostedFile.FileName.Split(new string[] {
- "."
- }, StringSplitOptions.None);
- extention = tokens[1];
-
- FileStream fs = new FileStream(filePath + fluDocument.PostedFile.FileName, FileMode.Open, FileAccess.Read, FileShare.Write);
- BinaryReader br = new BinaryReader(fs);
- Byte[] bytes = br.ReadBytes((Int32) fs.Length);
- br.Close();
- fs.Close();
- doc.DocumentContent = bytes;
-
- #
- region "Checking extention"
- if (extention == "pdf") {
- doc.ContentType = "application/" + extention;
- }
- if (extention == "jpg") {
- doc.ContentType = "image/" + extention;
- }
- if (extention == "xls") {
- doc.ContentType = "application/vnd.ms-excel";
- }
- if (extention == "xlsx") {
- doc.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
- }
- if (extention == "docx") {
- doc.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
- }
- if (extention == "doc") {
- doc.ContentType = "application/doc";
- }#
- endregion
-
- if (File.Exists(filePath + fluDocument.PostedFile.FileName)) {
- File.Delete(filePath + fluDocument.PostedFile.FileName);
- }
-
- }
If the segment in Pink is commented the program will route thru the doc object and saves the captured information in a table except the uploaded file.