protected void btnupload_mul_Click(object sender, EventArgs e) { DBHelperClass dBHelperClass = new DBHelperClass(); DataSet dataSet = new DataSet(); string fname = "", lname = "", doa = ""; foreach (HttpPostedFile postedFile in fupmul.PostedFiles) { //string[] fileName = Path.GetFileName(postedFile.FileName).Split(','); string fileName = Path.GetFileName(postedFile.FileName); string msg = ""; try { Regex re = new Regex(@"\d+"); Match m = re.Match(fileName); if (m.Success) { string file = fileName.Substring(0, m.Index); string[] str = file.Split(','); // lblResults.Text = string.Format("RegEx found " + m.Value + " at position " + m.Index.ToString() + " character in string is " + file + " fname: " + str[1] + ",LastName:" + str[0]); lname = str[0]; if (str[1].Contains("_")) { fname = str[1].Split('_')[0]; } else { fname = str[1]; } file = fileName; str = file.Split('_'); if (str.Length > 2) { doa = str[str.Length - 1].ToLower().Split('.')[0]; } } else { string[] str = fileName.Split('_'); fname = str[0].Split(',')[1]; lname = str[0].Split(',')[0]; } doa = CommonConvert.DateformatDOA(doa); doa = CommonConvert.DateFormat(doa); string[] strfname = fname.TrimStart().Split(' '); fname = strfname[0]; dataSet = dBHelperClass.selectData("select Patient_ID from tblPatientMaster where LastName='" + lname.Trim().TrimStart() + "' and FirstName='" + fname.Trim().TrimStart() + "'"); if (dataSet != null && dataSet.Tables[0].Rows.Count > 0) { string patientid = dataSet.Tables[0].Rows[0][0].ToString(); string upload_folder_path = "~/PatientDocument/" + patientid; if (!Directory.Exists(upload_folder_path)) { Directory.CreateDirectory(Server.MapPath(upload_folder_path)); } postedFile.SaveAs(System.IO.Path.Combine(Server.MapPath(upload_folder_path), fileName)); sb.Append("<p>File Name : " + fileName + " patientid:" + patientid + " Status : Uploaded </p>"); sb.Append(Environment.NewLine); Logger.Info("File Name : " + fileName + " patientid:" + patientid + " Status : Uploaded"); //string filename = System.DateTime.Now.Millisecond.ToString() + "_" + fileName; if (checkName(fileName, patientid) == false) { string filename = fileName; string query = "insert into tblPatientDocument values('" + filename + "','" + System.DateTime.Now.ToString() + "','" + upload_folder_path + "/" + filename + "'," + patientid + ",'" + doa + "')"; dBHelperClass.executeQuery(query); } } else { sb.Append("<p style='color:red'> File Name : " + fileName + " Status : Not Uploaded</p>"); sb.Append(Environment.NewLine); Logger.Info("File Name : " + fileName + " Status : Not Uploaded"); } } catch (Exception ex) { sb.Append("<p style='color:red'>File Name : " + fileName + " Status : Not Uploaded </p>"); Logger.Error("File Name : " + fileName + " Status : Not Uploaded \n"); } lblResult.InnerHtml = sb.ToString(); } }