如何在ASP .NET网站下载只读文件? [英] How to download file with read only in ASP .NET website?

查看:140
本文介绍了如何在ASP .NET网站下载只读文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器上有一个文件。服务器上的文件是只读的。当我将文件从ASP .NET应用程序下载到本地计算机时,该文件具有读写访问权限。删除了原始只读属性。我想下载文件只读模式。你能否为这个问题建议正确的解决方案



我尝试过:



我尝试了几个选项,比如使用response.transaferfile选项。

 Response.ContentType =test / plain; 
Response.AppendHeader(Content-Disposition,attachment; filename = MyFile.txt);
Response.TransmitFile(Server.MapPath(〜/ Files / MyFile.txt));
Response.End();





在服务器上,此文件具有只读属性,但如果我使用上面的下载代码,只读属性在客户端位置自动删除。我想在下载后阻止文件只读。请提出一些解决方案。

解决方案

你不能。服务器无法控制哪里 - 甚至如果 - 文件保存在客户端上,也没有对它应用的属性或权限。



无论如何你也不需要。如果用户编辑了文件的副本,则不会对服务器的副本产生任何影响。


如果您不希望用户对下载的信息进行任何更改,您需要将其转换为可以控制编辑的格式。



您可以使用PDF文件执行此操作,我认为您可以使用Office文档执行此操作好。

I have a file present on server. The file on server is read-only. When I download the file from ASP .NET application to my local machine, the file has read and write access both. The original read-only attribute removed. I want to download the file read-only mode. Could you please suggest the proper solution for this problem

What I have tried:

I have tried couple of options like using response.transaferfile option.

Response.ContentType = "test/plain";
Response.AppendHeader("Content-Disposition", "attachment; filename=MyFile.txt");
Response.TransmitFile(Server.MapPath("~/Files/MyFile.txt"));
Response.End();



On server, this file has read-only attribute, but if I download using above code, the read-only attribute remove automatically in client location. I want to prevent file read-only after downloading. Please suggest some solution.

解决方案

You can't. The server has no control over where - or even if - the file is saved on the client, nor what attributes or permissions are applied to it.

And you don't need to anyway. If the user edits their copy of the file, it won't have any effect on the server's copy.


If you don't want the user to make any changes to what information is downloaded, you need to convert it to a format that you can control editing.

You can do this with PDF files, and I think you can do it with Office documents as well.


这篇关于如何在ASP .NET网站下载只读文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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