日期:2014-05-17  浏览次数:20864 次

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;