在AD中存取照片
AD中有存放照片的字段吗?
答案肯定是有的、photo,jpegPhoto,thumbnailPhoto
前端时间客户,包括领导 在问通讯录中的照片为什么存在数据库中而不是AD中,AD中的属性能不能利用起来呢?
我想照片这么大的数据,如果用户量大的,应该是不建议存放在AD端的,不然为什么微软的ad管理器都没有照片的管理项呢?
但是既然领导问了,当然要去验证一下。。
答案肯定是有的、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

出处:http://www.cnblogs.com/xuanye/archive/2008/05/13/1195225.html
关注我】。(●'◡'●)
如果,您希望更容易地发现我的新博客,不妨点击一下绿色通道的【因为,我的写作热情也离不开您的肯定与支持,感谢您的阅读,我是【Jack_孟】!
本文来自博客园,作者:jack_Meng,转载请注明原文链接:https://www.cnblogs.com/mq0036/p/8482668.html
【免责声明】本文来自源于网络,如涉及版权或侵权问题,请及时联系我们,我们将第一时间删除或更改!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2017-02-28 C#中将dateTimePicker初始值设置为空
2014-02-28 MSG命令使用详解