.net中,将文件另存为

buhuiry01 2009-11-28 06:06:07
网站上有个.exe文件,当我点击一个button的时候需要将网站上的这个.exe保存到本地。
我的程序是这样的:
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=Status.exe");

Response.BufferOutput = false;
Response.ContentType = "application/exe";
Response.TransmitFile(FullFilePath);
Response.Flush();
Response.End();

但是这样的代码打开的窗口中有"run","save","cancel"三个按钮,现在我只想要"save"和"cancel"两个按钮,不要"run"可以吗?

或者说直接打开一个另存为的窗口,就像是IE中右键后“目标另存为”那样的窗口,可以吗?

我在网上找了一下,基本上都没法实现,而且方法都是2005年的,
例如:http://www.cnblogs.com/wubiyu/archive/2008/01/16/1041371.html
或者http://www.itokit.com/2009/1017/8939.html
这里面的方法我都试过了,还是会出现那三个按钮。。

求教高手。。。
...全文
439 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
如果能绕过安全检查,开发浏览器的软件公司(例如微软)就因该倒闭了。

你想,互联网上随便一个网站都可以对任意用户流氓安装木马,这可能吗?


唯一能的只是:首先欺骗用户,使其降低浏览器安全级别设置,或者事先安装一个流氓软件用来自动安装更多的流氓软件。
ajaxtop 2009-11-29
  • 打赏
  • 举报
回复
楼主,这样是想把远程文件下载到自己本地吗,要不就得看下windows编程了
buhuiry01 2009-11-29
  • 打赏
  • 举报
回复
来人救命啊
buhuiry01 2009-11-29
  • 打赏
  • 举报
回复
Up Up
wangminqi 2009-11-29
  • 打赏
  • 举报
回复
作成zip压缩文件 吧


http://www.mybuffet.cn
buhuiry01 2009-11-29
  • 打赏
  • 举报
回复
那能否换个方法,譬如说我点击一个链接:
www.xxxxx.com/images/status.exe
当我点击他的时候,有办法出现另存为对话框吗?
极地_雪狼 2009-11-28
  • 打赏
  • 举报
回复
好奇,关注。
buhuiry01 2009-11-28
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 wuyq11 的回复:]
存在安全性问题

  string fileName = "a.rar";
      string filePath = Server.MapPath("keji.rar");

        FileInfo fileInfo = new FileInfo(filePath);
        Response.Clear();
        Response.ClearContent();
        Response.ClearHeaders();
        Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
        Response.AddHeader("Content-Length", fileInfo.Length.ToString());
        Response.AddHeader("Content-Transfer-Encoding", "binary");
        Response.ContentType = "application/octet-stream";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
        Response.WriteFile(fileInfo.FullName);
        Response.Flush();
        Response.End();

[/Quote]

按照你写的代码,我试过了,还是不行啊。。代码如下:

string filePath = Server.MapPath("../images/" + filename + ".xml");
String Status = String.Empty;
Status = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><Method>sss</Method></root>";
XmlDocument docSave = new XmlDocument();
docSave.InnerXml = Status;
docSave.Save(filePath);


FileInfo fileInfo = new FileInfo(filePath);
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "attachment;filename=Status.xml");
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.WriteFile(fileInfo.FullName);
Response.Flush();
Response.End();

可是还是会出现三个按钮,能否让他直接另存为呢?
buhuiry01 2009-11-28
  • 打赏
  • 举报
回复
如果不能去掉那个"run"按钮,能不能直接打开另存为的对话框呢?
也就是说跳过带有"run" 的那个窗口。。。
wuyq11 2009-11-28
  • 打赏
  • 举报
回复
存在安全性问题

string fileName = "a.rar";
string filePath = Server.MapPath("keji.rar");

FileInfo fileInfo = new FileInfo(filePath);
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.WriteFile(fileInfo.FullName);
Response.Flush();
Response.End();
若情水 2009-11-28
  • 打赏
  • 举报
回复
偶来看看
lzsh0622 2009-11-28
  • 打赏
  • 举报
回复
观注

在windows下用WinAPI可以实现类似效果。

但是,在ASP.NET下,这个下载窗口不能实例化,没有设置窗口内控件属性的途径。
chen_ya_ping 2009-11-28
  • 打赏
  • 举报
回复
这个我想没有什么办法吧。其实有3个按钮我想没有什么影响吧。
cuike519 2009-11-28
  • 打赏
  • 举报
回复
这个不用ocx基本上不太可能。。。
buhuiry01 2009-11-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 fly_to_the_winds 的回复:]

[/Quote]

美女来帮忙啊~~
浮生若梦丶 2009-11-28
  • 打赏
  • 举报
回复

62,075

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧