答案確定是有的、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
