Click here to Skip to main content
15,917,709 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Updated 15-Feb-17 22:13pm

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900