Access photos in AD

Source: Internet
Author: User
Tags samaccountname
Is there a field for storing photos in ad?
The answer must be yes, photo, jpegphoto, and thumbnailphoto.

The front-end customers, including the leaders, asked why the photos in the address book exist in the Database rather than in the ad. Can the attributes in the ad be used?
I think it is not recommended to store large volumes of data such as photos on the ad end if there are a large number of users. Otherwise, why does Microsoft's ad manager have no photo management items?

But now that the leader asks, verify it ..

1
2 // Obtains the object of the user object to be modified.
3 Private Directoryentry getdirectoryentryby ( String Samaccountname)
4 {
5 String Path = " LDAP: // pcdc01.company.com/ouyun Shanghai xxsoftware Co., Ltd., dc1_company,dc1_com " ;
6 Directoryentry rootde =   New Directoryentry (path, " Userid " , " PWD " ); // Access user
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 // BelowCodeIs to retrieve images from AD
2
3 String Account =   This . Tbaccount. text;
4 If (Account =   "" )
5 {
6 MessageBox. Show ( " Enter an account " );
7 Return ;
8 }
9 Directoryentry de = Getdirectoryentryby (account );
10 If (De =   Null )
11 {
12 MessageBox. Show ( " Invalid account " );
13 Return ;
14 }
15 String Photocol =   This . Cbbphotocol. text; // Select one of the three fields to access the photo.
16
17 System. directoryservices. propertyvaluecollection PVC = De. properties [photocol];
18 If (PVC. Value ! =   Null   && PVC. Value Is   Byte [])
19 {
20 Byte [] = ( Byte []) PVC. value;
21 Memorystream stream =   New Memorystream ();
22 This . Pbcontainer. Image = Image. fromstream (Stream );
23 }
24 Else
25 {
26 MessageBox. Show ( " False " );
27 } 1  
2 Save the photo to AD
3
4 String Account =   This . Tbaccount. text;
5 If (Account =   "" )
6 {
7MessageBox. Show ("Enter an account");
8Return;
9}
10
11 String CC =   This . Textbox1.text;
12 If (CC =   "" )
13 {
14MessageBox. Show ("Select Image");
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 {
25MessageBox. Show ("Invalid account");
26Return;
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 ( " Updated " );
33 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.