asp.net中,在生成打印word文档时同时自动保存在一个指定的文件夹里 妹子急求大神指点迷津!!!在线等

2026年09月25日 07:18
有2个网友回答
网友(1):

//流方式下载
protected void Button4_Click(object sender, EventArgs e)
{
string fileName = "aaa.zip";//客户端保存的文件名
string filePath = Server.MapPath("DownLoad/aaa.zip");//路径
//以字符流的形式下载文件
FileStream fs = new FileStream(filePath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
//通知浏览器下载文件而不是打开
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}

网友(2):

用PageOffice很简单,网上搜有很多示例代码的