none
Document not in given format RRS feed

  • Question

  •  tokens = fluDocument.PostedFile.FileName.Split(new string[] { "." }, StringSplitOptions.None);
                    extention = tokens[1];
                    FileStream fs = new FileStream(filePath + fluDocument.PostedFile.FileName, FileMode.Open, FileAccess.Read);
                    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;
                    }

    The document posted in fludocument and saved in side fileUploads folder cannot be retrieved and saved inside the sql server database

    Saturday, October 12, 2019 5:04 PM

Answers

  • Hi hari66,

    Thank you for posting here.

    According to your description, I need more information to make a test.

    Could you provide more code about 'fluDocument', 'doc' and some code about document cannot be savd inside the sql server database? It will help us to analyze your problem.

    We are waiting for your update.

    Best Regards,

    Xingyu Zhao 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by hari66 Saturday, October 19, 2019 5:27 PM
    Monday, October 14, 2019 6:13 AM
    Moderator

All replies

  • Hi hari66,

    Thank you for posting here.

    According to your description, I need more information to make a test.

    Could you provide more code about 'fluDocument', 'doc' and some code about document cannot be savd inside the sql server database? It will help us to analyze your problem.

    We are waiting for your update.

    Best Regards,

    Xingyu Zhao 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by hari66 Saturday, October 19, 2019 5:27 PM
    Monday, October 14, 2019 6:13 AM
    Moderator
  • Thank you Xingyu Zhao ,

    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);
                    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);
                    }

                }
                doc.CaptureDate = Convert.ToDateTime (txtDate.Text);           
                doc.CaptureLocation = int.Parse(Session["location"].ToString());
                doc.RefDocType = int.Parse(ddlDocType.SelectedValue);
                doc.FileName = fluDocument.PostedFile.FileName;
                doc.DocumentStatus = (int)DocumentTypes.InitiateDocument;
                //Add Location Details
                EntitySet<DDS_DocumentLocation> locList = new EntitySet<DDS_DocumentLocation>();
                foreach (GridViewRow row in gvLocations.Rows)
                {
                    DDS_DocumentLocation loc = new DDS_DocumentLocation();

                    CheckBox ddlId = (CheckBox)row.FindControl("chkItem");
                    if (ddlId!=null && ddlId.Checked)
                    {
                 Label txtLocation = (Label)row.FindControl("lblLocationDate");
                 loc.DispatchedLocation = int.Parse(txtLocation.Text);
                 loc.RefDocument = doc.Id;
                 locList.Add(loc);
                 locationChecked = true;
                        }



                }
                if (locationChecked==false)
                {
                    ScriptManager.RegisterStartupScript(Page, this.GetType(), "alert", string.Format("alert('{0}');", "Please select Atleast one Dispatch location"), true);
                    return;
                }
                //End Add locations
                doc.DDS_DocumentLocations = locList;

                //Add Document Controls
                EntitySet<DDS_DocumentControlRecord> docControlList = new EntitySet<DDS_DocumentControlRecord>();
                DDS_DocumentControlRecord docControl = new DDS_DocumentControlRecord();
                docControl.RefDocId = doc.Id;
                docControl.RecordType = (int)DocumentTypes.InitiateDocument;
                MDM_Employee emp = (MDM_Employee)Session["employee"];
                docControl.RefEmp = emp.Id;
                docControl.RecordDate = Convert.ToDateTime(DateTime.Now.ToShortDateString());
                docControlList.Add(docControl);
                doc.DDS_DocumentControlRecords = docControlList;
                documentUC = new DocumentUC();

                if (documentUC.SaveDocument(doc, "Capture"))
                {
                    ScriptManager.RegisterStartupScript(Page, this.GetType(), "alert", string.Format("alert('{0}');", "Document Sucessfully Saved"), true);
                    return;

                }
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(Page, this.GetType(), "alert", string.Format("alert('{0}');", "Document not Saved"), false);
                return;

            }
        }

      FileStream fs = new FileStream(filePath + fluDocument.PostedFile.FileName, FileMode.Open, FileAccess.Read);

    using the breakpoints, i observed that the code executes up to here, showing the fluDocument (it can be found in the uploads folder) 

    According to the code, it shows in the fs (which is posted in the folder), cannot be read by the Binary Reader, then the pointer jumps to the exception, throwing a message "Document not Saved"

                                                              
    Saturday, October 19, 2019 5:36 PM