62,046
社区成员
发帖
与我相关
我的任务
分享
PurchaseOrderParam pop = ReturnParamByUrl();
// pop.PageSize = endIndex;
// IPagedList<PurchaseOrderDetail> list = poService.GetPurchaseOrderDetailList(pop);
// if (list == null)
// return;
// if (list != null)
// {
// System.Web.HttpContext curContext = System.Web.HttpContext.Current;
// curContext.Response.Clear();
// if (endIndex <= 0 || endIndex > list.TotalCount)
// endIndex = list.TotalCount;
// // 设置编码和附件格式
// curContext.Response.ContentType = "application/vnd.ms-excel";
// curContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
// curContext.Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(fileName, Encoding.GetEncoding("gb2312")) + "." + fileType);
// curContext.Response.Flush();
// StringBuilder sb = new StringBuilder();
// StringBuilder sbline = new StringBuilder();
// string coltmp = fileType.ToLower() == "csv" ? "\"{0}\"," : "{0},";
// int itemp = 0;
// XmlDocument doc = new XmlDocument();
// doc.Load(Server.MapPath("~/App_Data/ExportFormart.xml"));
// XmlNodeList xmlNodeList = doc.SelectNodes("//FileFormats/FileFormat[@TbColumn='" + column + "']/Field[@Display='True']");
// foreach (XmlNode xdcolName in xmlNodeList)
// sbline.Append(string.Format(coltmp, xdcolName.Attributes["Description"].Value));
// if (sbline.Length == 0)
// return;
// sbline.ToString().Remove(sbline.Length - 1);
// sb.AppendLine(sbline.ToString());
// sbline.Remove(0, sbline.Length);
// foreach (PurchaseOrderDetail pod in list.InnerList)
// {
// if (itemp == endIndex)
// break;
// sbline.Remove(0, sbline.Length);
// foreach (XmlNode xdcolValue in xmlNodeList)
// {
// string fieldName = xdcolValue.Attributes["Name"].Value;
// if (!string.IsNullOrEmpty(fieldName))
// {
// object value;
// PropertyInfo p = pod.GetType().GetProperty(fieldName);
// if (p == null)
// {
// Entity.Goods gd = new Entity.Goods();
// gd = pod.Goods;
// value = gd.GetType().GetProperty(fieldName).GetValue(gd, null);
// }
// else
// value = p.GetValue(pod, null);
// if (value == null)
// {
// sbline.Append(string.Format(coltmp, ""));
// continue;
// }
// else
// {
// if (fieldName == "Status")
// {
// if (value.ToString() == "1") value = "未处理";
// else if (value.ToString() == "2") value = "已处理";
// else if (value.ToString() == "3") value = "取消";
// else if (value.ToString() == "4") value = "结案";
// }
// }
// sbline.Append(string.Format(coltmp, value.ToString()));
// }
// }
// sb.AppendLine(sbline.ToString());
// itemp++;
// }
// curContext.Response.Write(sb.ToString());
// curContext.Response.End();
// }
string path = Server.MapPath(@"~\file\test.pdf");
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ClearHeaders();
response.Buffer = true;
Encoding code = Encoding.GetEncoding("GB2312");
response.ContentEncoding = code;
response.HeaderEncoding = code;
response.AddHeader("Content-Type", "application/octet-stream");
response.AppendHeader("Content-Disposition", "filename=test.pdf");
response.WriteFile(path);
response.Flush();
response.Close();