强制浏览器将下载的文件保存在特定位置 [英] Force the browser to save downloaded file in a specific location

查看:128
本文介绍了强制浏览器将下载的文件保存在特定位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目是 Asp.Net MVC4 Web应用程序.

My project is an Asp.Net MVC4 web application.

当前,它具有一种生成文本文件并将其发送到客户端浏览器进行下载的方法.

Currently it has a method to generate a text file and send it to the client's browser for download.

我需要对其进行修改,以强制浏览器将文件保存在客户端计算机上的自定义(预定义)位置.

I need to modify it to force the browser to save the file in a custom (pre-defined) location on the client's computer.

推荐答案

这将是不可能的,因为它会带来严重的安全问题.用户必须决定文件的保存位置.

This will not be possible as it would introduce a severe security problem. A user has to decide where the file will be saved.

您只能在服务器上指定有权访问的位置.

You can only specify a location on a server to which you have access to.

如果它是内部站点,则可以设置服务器以将文件保存到网络位置,然后将该路径返回给用户.

If its an internal site, then you could setup the server to save the file to a network location and return that path to the user..

如果要显示另存为,请将其添加到ActionResult中以指示文件已下载:

If you want to show a save as, add this to your ActionResult to indicate a file download:

Response.SetCookie(new HttpCookie("fileDownload", "true") { Path = "/" });
return myFileStreamResult

这篇关于强制浏览器将下载的文件保存在特定位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆