如何在MVC中下载只读文件 [英] How to download a read only file in MVC

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

问题描述

我想使用文件结果返回mvc中的只读文件



我的代码是



我尝试过:



I want to return a read only file in mvc using file result

My Code is

What I have tried:

<pre>public FileResult Download(string FileName)
        {
            byte[] fileBytes = System.IO.File.ReadAllBytes(Server.MapPath(@"~\Path\" + FileName));
            string fileName = FileName;
            return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
        }





下载工作但只读属性已从下载的文件中删除



如何修复它



download is working but Read only Attributes is removed from downloaded file

how to fix it

推荐答案

你如何定义文件是只读?如果您在文件中设置它,那么这些是附加到FAT32或NTFS文件系统中的文件的属性,该文件是只读的事实不是文件数据的一部分,并且当您将文件流式传输到客户端它只是您发送的数据。如果您要向不使用FAT32 \ NTFS的人发送文件怎么办?如果用户的操作系统根本不支持只读文件会怎么样?



基本上你不能做什么。许多文档类型(如PDF,Word等)都有允许您保护它们的方法,因此您应该使用基础文件类型本身支持的任何功能(如果有的话)。
How are you defining the file is "read only"? If you are setting it on the file then those are attributes attached to the file in the FAT32 or NTFS file system, the fact that the file is read-only is not a part of the file's data, and when you stream a file to the client it is only the data you are sending. What if you are sending a file to someone not using FAT32\NTFS? What if the user has an OS that doesn't support read-only files at all?

Basically what you are doing isn't possible. Many document types like PDF, Word etc have ways of allowing you to protect them so you should use whatever features are supported by the underlying file type itself, if any.


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

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