1
///
<summary>
2
///
为创建的临时文件分配权限
3
///
</summary>
4
///
<param name="pathname"></param>
5
///
<param name="username"></param>
6
///
<param name="power"></param>
7
///
<remarks>
SKY 2007-8-6
</remarks>
8
public
void
addpathPower(
string
pathname,
string
username,
string
power)
9
{
10
11
DirectoryInfo dirinfo
=
new
DirectoryInfo(pathname);
12
13
if
((dirinfo.Attributes
&
FileAttributes.ReadOnly)
!=
0
)
14
{
15
dirinfo.Attributes
=
FileAttributes.Normal;
16
}
17
18
//
取得访问控制列表
19
DirectorySecurity dirsecurity
=
dirinfo.GetAccessControl();
20
21
switch
(power)
22
{
23
case
"
FullControl
"
:
24
dirsecurity.AddAccessRule(
new
FileSystemAccessRule(username, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow));
25
break
;
26
case
"
ReadOnly
"
:
27
dirsecurity.AddAccessRule(
new
FileSystemAccessRule(username, FileSystemRights.Read, AccessControlType.Allow));
28
break
;
29
case
"
Write
"
:
30
dirsecurity.AddAccessRule(
new
FileSystemAccessRule(username, FileSystemRights.Write, AccessControlType.Allow));
31
break
;
32
case
"
Modify
"
:
33
dirsecurity.AddAccessRule(
new
FileSystemAccessRule(username, FileSystemRights.Modify, AccessControlType.Allow));
34
break
;
35
}
36
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

DirectoryInfo是需要实例化的,而且实例化的时候必须指定文件夹路径,Directory则是静态类.
主程序中调用的写法:
1
private
void
CreateDirectory()
2
{
3
4
addpathPower(sPath,
"
ASPNET
"
,
"
FullControl
"
);
5
6
}

2

3


4

5


6

http://www.cnblogs.com/leosky2008/archive/2007/08/08/847405.html