Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
In our project we have to send data to other users in C#. But users should not modify the file. Only he may able to read the file. If user wants to send the file to anyone then he may send as it is the received file without modifying it.
Posted

I don't think the kind of control you're talking about is possible, at least not with an RTF file. Here[^] is a way of making a Word document read-only, but it's easily circumvented.
 
Share this answer
 
Two ways to achieve it:

C#
System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
fileInfo.IsReadOnly = true/false;


IsReadOnly property on FileInfo essentially does the bit-flipping you would have to do manually in the second method.

C#
File.SetAttributes(filePath, FileAttributes.ReadOnly/FileAttributes.Normal);
 
Share this answer
 
Comments
Marc A. Brown 16-Mar-12 11:58am    
Yeah, I thought about throwing that bit in there as well, but as with my answer it's a fairly pointless exercise since it's so easily circumvented. Not sure why either of our answers got downvoted though since both are correct. I'll help compensate for the downvote on your answer. Have a 5. :)
Dave Kreskowiak 30-Sep-15 10:13am    
The problem with this is that the file attributes are so easily defeated that it's not even worth the time to write the code. On top of that, the attributes can also be stripped completely depending on how the file is "sent" to the users.

Marc's answer below is actually far more accurate.

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