public string GcntlSalesP20TextData(string id) { var responseStr = "";//Define an empty string to receive the required data if (string.IsNullOrWhiteSpace(id))//Determine whether the id is empty return ""; DataTable dtTrgpaxList = this._trGPaxService.GetTrgpaxByGrupCdP20t(id); if (dtTrgpaxList != null && dtTrgpaxList.Rows.Count > 0) { var strPaxCds = ""; var strPaxCnms = ""; for (int i = 0, j = dtTrgpaxList.Rows.Count; i < j; i++) { strPaxCds = dtTrgpaxList.Rows[i]["PAX_CD"].ToString(); strPaxCnms = dtTrgpaxList.Rows[i]["PAX_CNM"].ToString(); DataTable dtTrpaxList = this._trpaxService.GetTrpaxByPaxCdP20t(strPaxCds); if (dtTrpaxList != null && dtTrpaxList.Rows.Count > 0) { var strPaxIdno = ""; var strPaxBrthdt = ""; for (int a = 0, b = dtTrpaxList.Rows.Count; a < b; a++) { strPaxIdno = dtTrpaxList.Rows[a]["ID_NO"].ToString(); strPaxBrthdt = dtTrpaxList.Rows[a]["BRTH_DT"].ToString(); strPaxBrthdt = strPaxBrthdt.Replace("/", ""); if (strPaxIdno == "") { strPaxIdno = " "; } if (strPaxBrthdt == "") { strPaxBrthdt = " "; } string strResponse = strPaxIdno + "," + strPaxBrthdt + "," + strPaxCnms; responseStr += strResponse + "\r\n";//回車 } } else { string strResponse = " ," + " ," + strPaxCnms; responseStr += strResponse + "\r\n";//回車 } } } return responseStr; }
Create a notepad
public void GcntlSalesP20Text(string id) { var MailBody = this.GcntlSalesP20TextData(id);//Get data if (!string.IsNullOrWhiteSpace(MailBody))//Judging that the character is not empty, if it is not empty, execute the following statement { //create notepad string strUserId = System.Web.HttpContext.Current.User.Identity.Name; string strDateTime = System.DateTime.Now.ToString("yyyyMMddHHmmss"); //Details of foreign bookings_(user code)_(system time) string fileStrB = id + "_" + strDateTime; // before encryption byte[] result = Encoding.Default.GetBytes(fileStrB); MD5 md5 = new MD5CryptoServiceProvider(); byte[] output = md5.ComputeHash(result); string fileName = BitConverter.ToString(output).ToString().Replace("-", "").ToLower() + ".txt";//加密後 string path = Server.MapPath(@"~\upload\"); if (!System.IO.Directory.Exists(path)) // Determine if the folder exists, if not, create it System.IO.Directory.CreateDirectory(path); // write to client Response.Clear(); //Add an HTTP header to the output stream Response.AddHeader("content-disposition", "attachment;filename=" + fileName); //Set the output HTTP type Response.ContentType = "application/text/xml"; //Write the character array to the corresponding HTTP output stream Response.Write(MailBody); // after sending, close Response.End(); } else { Response.AddHeader("Content-type", "text/html;charset=UTF-8"); Response.Flush(); Response.Write(MailBody); } }