By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,152 Members | 1,402 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,152 IT Pros & Developers. It's quick & easy.

Reg : File Readonly

P: n/a
Hi

Can you please explain me how to make a text file as a Read Only which is
already existing in local disk in C#.

Thanks
Siva.
Mar 31 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Create a FileInfo object for the file you are interested in, and then add the
"FileAttributes.ReadOnly" flag to the Attributes property.

For example (error checks left out for clarity):

string sFileName = "C:\\test.txt";

FileInfo fiInfo = new FileInfo(sFileName);
fiInfo.Attributes += FileAttributes.ReadOnly;
"SivaprakashShanmugam" wrote:
Hi

Can you please explain me how to make a text file as a Read Only which is
already existing in local disk in C#.

Thanks
Siva.

Mar 31 '06 #2

P: n/a
FileInfo f= new FileInfo(@"c:\good.txt");
if(!f.Exists)
f.Create();

f.Attributes=FileAttributes.ReadOnly;
f.Refresh();

Mar 31 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.