user724240
user724240

Reputation: 1

how to protect my files from editing in C#

I am new to C# , i wrote one application its contain directories and some file , i dont want to edit these file from outside of the program or manually , plz tell me how to do that if u provide the code that will be very usefull.

Thx

Upvotes: 0

Views: 604

Answers (3)

mcw
mcw

Reputation: 3596

Are you just reading from these files or writing to them? If you're just reading them, you might embed them as resources in your compiled output rather than keeping them as files on disk.

http://support.microsoft.com/kb/319292

Upvotes: 0

jac
jac

Reputation: 9726

You can set the read only attribute. It is only a minor inconvenience to someone who wants to edit a file, but you haven't got much control over what a user does outside of your program. At least if a user clears the read only attribute and changes your file you can blame them for it.

System.IO.File.SetAttributes("path\\file", FileAttributes.ReadOnly)

Upvotes: 0

mservidio
mservidio

Reputation: 13057

There is no real way to protect from within the application. If you're storing these files on a file system, they will be accesible based on file system permissions. You could store information in a password protected database or something similiar in order to make it only accessible to the application.

Actually on second thought, you may be able to save these files within a resource bundle. I'm not sure if that is entirely protected though.

Upvotes: 3

Related Questions