17,740
社区成员
发帖
与我相关
我的任务
分享
protected void Button1_Click(object sender, EventArgs e)
{
try
{
string filepath = "tmp/" + fd.ha_User.UID + "-11.doc";
File.Copy(Server.MapPath("./templet/11.doc"), Server.MapPath(filepath), true);
//Document doc = new Document();
doc.LoadFromFile(Server.MapPath(filepath), Spire.Doc.FileFormat.Docx);
doc.Replace("zhi", fd.ha_User.Ucity, false, true);
doc.Replace("lhao", fd.FD_LouPan.Lname + fd.Fhousehao, false, true);
doc.Replace("shoufu", (Convert.ToDouble(fd.Fshoufu) / 10000).ToString(), false, true);
doc.Replace("sfz", fd.Fsfz, false, false);
doc.SaveToFile(Server.MapPath(filepath));
downloadfile(Server.MapPath(filepath));
}
catch (Exception ex)
{
PageHelper.Alert(ex.Message);
}
}
void downloadfile(string s_path)
{
System.IO.FileInfo file = new System.IO.FileInfo(s_path);
HttpContext.Current.Response.ContentType = "application/ms-download";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Type", "application/octet-stream");
HttpContext.Current.Response.Charset = "utf-8";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8));
HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
HttpContext.Current.Response.WriteFile(file.FullName);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Clear();
HttpContext.Current.ApplicationInstance.CompleteRequest();
//HttpContext.Current.Response.End();
}