示例#1
0
        public static string AddDocuments(HttpRequestBase Request, List <Tbl_Document_List> Doclist,
                                          string fileSavePathMain, string Appno, int Custid)
        {
            string results = "";

            if (Request.Files.AllKeys.Length > 0)
            {
                BirthProcessAction obj = new BirthProcessAction();
                for (int k = 0; k < Doclist.Count; k++)
                {
                    string fileSavePath = fileSavePathMain;//added this-Soumendu
                    var    DocumentTmp  = Doclist[k];
                    var    files        = Request.Files;

                    var file = files[k];
                    if (file != null)
                    {
                        var fileName = file.FileName;
                        if (fileName != null && fileName.Trim().Length > 0)
                        {
                            if (fileName.Contains(@"\"))
                            {
                                fileName = fileName.Substring(fileName.LastIndexOf(@"\"));
                            }
                            string Docname = DocumentTmp.Docname;

                            if (Docname.Equals("Identity Document"))
                            {
                                Docname = Docname.Replace(" ", "_");
                            }
                            else
                            {
                                string[] temp = Appno.Split('_');
                                Docname = temp[0];
                            }

                            int    idx          = fileName.LastIndexOf(".");
                            string fileNameTemp = fileName.Substring(0, idx);
                            string extemp       = fileName.Substring(idx);
                            fileNameTemp = fileNameTemp + "_" + Appno;
                            fileName     = fileNameTemp + extemp;

                            fileSavePath = fileSavePath + Docname;
                            if (!Directory.Exists(fileSavePath))
                            {
                                Directory.CreateDirectory(fileSavePath);
                            }

                            fileSavePath = fileSavePath + "\\" + fileName;


                            //populate DocumentTmp
                            DocumentTmp.DocFilePath = fileSavePath;
                            DocumentTmp.IsActive    = true;
                            DocumentTmp.BR_ID       = Appno;
                            DocumentTmp.Doctype     = Doclist[k].Doctype;
                            results = results + obj.InsertDocumentAttachment(DocumentTmp.BR_ID, fileName,
                                                                             DocumentTmp.DocFilePath, DocumentTmp.Doctype, DocumentTmp.IsActive, Custid);
                            file.SaveAs(fileSavePath);
                        }
                    }
                }
            }
            return(results);
        }