首页 新闻 赞助 找找看

asp.net导出问题 浏览器怎么弹出保存文件对话框

0
悬赏园豆:20 [已解决问题] 解决于 2014-07-22 09:59

做的导出功能,现在是写死的保存在桌面上,导出功能浏览器不是会弹出对话框选择保存路径吗?那个要怎么写?

 for (int i = 0; i < table.Rows.Count; i++)
                {
                    Row row = sheettemp.CreateRow(i + 1);
                    row.CreateCell(0).SetCellValue(table.Rows[i][0].ToString());
                    row.CreateCell(1).SetCellValue(table.Rows[i][5].ToString());
                }
                sheettemp.ForceFormulaRecalculation = true;

                using (FileStream filewrite = new FileStream(@"C:\Users\Administrator\Desktop\" + string.Concat("报销报表", DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss")), FileMode.Create))
                {
                    h.Write(filewrite);
                    filewrite.Close();
                }

 

现在是这样 写死的路径  for循环以及之上都是组装excel的代码 我要怎么写  能让浏览器弹出保存文件的对话框??

问题补充:

 框架限制的问题。我重写一个空aspx页面 到那里操作了  和二楼的类似

战马的主页 战马 | 初学一级 | 园豆:27
提问于:2014-07-21 11:28
< >
分享
最佳答案
0

1、其实你的所有操作目前都是在服务器端运行,包括路径的指向。

2、你可以先保存到服务器的临时目录,然后

Response.ContentType = "application/x-zip-compressed";
  Response.AddHeader("Content-Disposition", "attachment;filename=z.zip");
  string filename = Server.MapPath("DownLoad/aaa.zip");
  Response.TransmitFile(filename);

3 内容写入Response的流中,然后输出。

百度下就知道了

收获园豆:20
waiter | 小虾三级 |园豆:1000 | 2014-07-21 12:33
其他回答(2)
0

在 Header 中添加文件类型。

Launcher | 园豆:45045 (高人七级) | 2014-07-21 11:33
0

Response.Redirect("文件路径");  最简单的方式,使用浏览器的 下载

wolfy | 园豆:2636 (老鸟四级) | 2014-07-21 13:21
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册