471,089 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 software developers and data experts.

Reg : File Readonly

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
2 1538
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
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.

Similar topics

3 posts views Thread by David Elliott | last post: by
9 posts views Thread by ALI-R | last post: by
2 posts views Thread by David Krmpotic | last post: by
2 posts views Thread by Jarod_24 | last post: by
5 posts views Thread by IcingDeath via DotNetMonster.com | last post: by
3 posts views Thread by Mayur H Chauhan | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.