答案肯定是有的、photo,jpegPhoto,thumbnailPhoto
前端时间客户,包括领导 在问通讯录中的照片为什么存在数据库中而不是AD中,AD中的属性能不能利用起来呢?
我想照片这么大的数据,如果用户量大的,应该是不建议存放在AD端的,不然为什么微软的ad管理器都没有照片的管理项呢?
但是既然领导问了,当然要去验证一下。。
1
2 //获取需要修改的用户对象实体
3 private DirectoryEntry getDirectoryEntryBy(string samAccountName)
4 {
5 string path="LDAP://pcdc01.company.com/OU=上海XX软件有限公司,dc=company,dc=com";
6 DirectoryEntry rootde = new DirectoryEntry(path, "userid", "pwd"); //访问用户
7 DirectorySearcher ds = new DirectorySearcher(rootde);
8 ds.SearchScope = SearchScope.Subtree;
9 ds.Filter = "(&(&(objectCategory=person)(objectClass=user))(sAMAccountName=" + samAccountName + "))";
10 SearchResult sr = ds.FindOne();
11 if (sr != null)
12 {
13 return sr.GetDirectoryEntry();
14 }
15 else
16 {
17 return null;
18 }
19 }
2 //获取需要修改的用户对象实体
3 private DirectoryEntry getDirectoryEntryBy(string samAccountName)
4 {
5 string path="LDAP://pcdc01.company.com/OU=上海XX软件有限公司,dc=company,dc=com";
6 DirectoryEntry rootde = new DirectoryEntry(path, "userid", "pwd"); //访问用户
7 DirectorySearcher ds = new DirectorySearcher(rootde);
8 ds.SearchScope = SearchScope.Subtree;
9 ds.Filter = "(&(&(objectCategory=person)(objectClass=user))(sAMAccountName=" + samAccountName + "))";
10 SearchResult sr = ds.FindOne();
11 if (sr != null)
12 {
13 return sr.GetDirectoryEntry();
14 }
15 else
16 {
17 return null;
18 }
19 }
1 //以下代码是从AD中取图片
2
3 string account = this.tbAccount.Text;
4 if ( account == "" )
5 {
6 MessageBox.Show("请填写帐号");
7 return;
8 }
9 DirectoryEntry de = getDirectoryEntryBy(account);
10 if (de == null)
11 {
12 MessageBox.Show("帐号无效");
13 return;
14 }
15 string photocol = this.cbbPhotoCol.Text; //那个字段存取照片,三个中选一个
16
17 System.DirectoryServices.PropertyValueCollection pvc = de.Properties[photocol];
18 if (pvc.Value != null && pvc.Value is byte[])
19 {
20 byte[] by = (byte[])pvc.Value;
21 MemoryStream Stream = new MemoryStream(by);
22 this.pbcontainer.Image = Image.FromStream(Stream);
23 }
24 else
25 {
26 MessageBox.Show("False");
27 }
2
3 string account = this.tbAccount.Text;
4 if ( account == "" )
5 {
6 MessageBox.Show("请填写帐号");
7 return;
8 }
9 DirectoryEntry de = getDirectoryEntryBy(account);
10 if (de == null)
11 {
12 MessageBox.Show("帐号无效");
13 return;
14 }
15 string photocol = this.cbbPhotoCol.Text; //那个字段存取照片,三个中选一个
16
17 System.DirectoryServices.PropertyValueCollection pvc = de.Properties[photocol];
18 if (pvc.Value != null && pvc.Value is byte[])
19 {
20 byte[] by = (byte[])pvc.Value;
21 MemoryStream Stream = new MemoryStream(by);
22 this.pbcontainer.Image = Image.FromStream(Stream);
23 }
24 else
25 {
26 MessageBox.Show("False");
27 }
1
2
将照片存到AD中
3
4
string account = this.tbAccount.Text;
5
if (account == "")
6
{
7
MessageBox.Show("请填写帐号");
8
return;
9
}
10
11
string cc = this.textBox1.Text;
12
if (cc == "")
13
{
14
MessageBox.Show("请选择图片");
15
}
16
else
17
{
18
Image im= Image.FromFile(cc);
19
MemoryStream Stream = new MemoryStream();
20
im.Save(Stream, System.Drawing.Imaging.ImageFormat.Jpeg);
21
byte[] bb=Stream.GetBuffer();
22
DirectoryEntry de = getDirectoryEntryBy(this.tbAccount.Text);
23
if (de == null)
24
{
25
MessageBox.Show("帐号无效");
26
return;
27
}
28
string photocol = this.cbbPhotoCol.Text;
29
System.DirectoryServices.PropertyValueCollection pvc = de.Properties[photocol];
30
pvc.Value = bb;
31
de.CommitChanges();
32
MessageBox.Show("更新成功");
33
}

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
