读书人

c# 如何设置文件或文件夹的属性 和访

发布时间: 2013-06-19 10:26:41 作者: rapoo

c# 怎么设置文件或文件夹的属性 和访问权限
if (!File.Exists(fullPath))
{
File.Create(fullPath);
}
以上代码为创建文件 ,怎么设置这个文件为只读.

求代码
[解决办法]
System.IO.File.SetAttributes
[解决办法]

File.SetAttributes(fullPath, FileAttributes.ReadOnly);

[解决办法]
FileStream f = File.Create("path");
f.Close();
File.OpenRead("path");
[解决办法]
            System.IO.FileInfo info=new System.IO.FileInfo(fullPath);
info.Attributes
[解决办法]
= System.IO.FileAttributes.ReadOnly;

读书人网 >C#

热点推荐