日期:2014-05-19  浏览次数:20430 次

如何用代码把页面保存成word文件并放在客户端的硬盘上?
就是做一个按钮,操作员点击一下就把页面保存成word文档,下载到客户机器里

------解决方案--------------------
System.IO.MemoryStream ms = new System.IO.MemoryStream();
// Write MemeoryStream
ds.WriteXml(ms,System.Data.XmlWriteMode.IgnoreSchema);
Response.Clear();
// filename & attachment
Response.AddHeader( "Content-Disposition ", "attachment; filename=xx.doc ");
// size of the file,to show process of downloading
Response.AddHeader( "Content-Lengt ", ms.Length.ToString());
// mode:download
Response.ContentType = "application/octet-stream ";
// sending to client
byte[] b = ms.ToArray();
Response.OutputStream.Write(b,0,b.Length);
Response.End();

------解决方案--------------------
BS程序由于IE安全问题,您并不能直接将文件保存在客户端.只能提供下载的形式供用户下载,自己保存.