AD中有存放照片的字段吗?
答案肯定是有的、photo,jpegPhoto,thumbnailPhoto
答案肯定是有的、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 + "))";
SearchResult sr = ds.FindOne();
if (sr != null)
{
return sr.GetDirectoryEntry();
}
else
{
return null;
}
}
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 + "))";
SearchResult sr = ds.FindOne();
if (sr != null)
{
return sr.GetDirectoryEntry();
}
else
{
return null;
}
}
1 //以下代码是从AD中取图片
2
3 string account = this.tbAccount.Text;
4 if ( account == "" )
5 {
6 MessageBox.Show("请填写帐号");
7 return;
8 }
9 DirectoryEntry de = getDirectoryEntryBy(account);
if (de == null)
{
MessageBox.Show("帐号无效");
return;
}
string photocol = this.cbbPhotoCol.Text; //那个字段存取照片,三个中选一个
System.DirectoryServices.PropertyValueCollection pvc = de.Properties[photocol];
if (pvc.Value != null && pvc.Value is byte[])
{
byte[] by = (byte[])pvc.Value;
MemoryStream Stream = new MemoryStream(by);
this.pbcontainer.Image = Image.FromStream(Stream);
}
else
{
MessageBox.Show("False");
}
2
3 string account = this.tbAccount.Text;
4 if ( account == "" )
5 {
6 MessageBox.Show("请填写帐号");
7 return;
8 }
9 DirectoryEntry de = getDirectoryEntryBy(account);
if (de == null)
{
MessageBox.Show("帐号无效");
return;
}
string photocol = this.cbbPhotoCol.Text; //那个字段存取照片,三个中选一个
System.DirectoryServices.PropertyValueCollection pvc = de.Properties[photocol];
if (pvc.Value != null && pvc.Value is byte[])
{
byte[] by = (byte[])pvc.Value;
MemoryStream Stream = new MemoryStream(by);
this.pbcontainer.Image = Image.FromStream(Stream);
}
else
{
MessageBox.Show("False");
}
1
2将照片存到AD中
3
4string account = this.tbAccount.Text;
5 if (account == "")
6 {
7 MessageBox.Show("请填写帐号");
8 return;
9 }
string cc = this.textBox1.Text;
if (cc == "")
{
MessageBox.Show("请选择图片");
}
else
{
Image im= Image.FromFile(cc);
MemoryStream Stream = new MemoryStream();
im.Save(Stream, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] bb=Stream.GetBuffer();
DirectoryEntry de = getDirectoryEntryBy(this.tbAccount.Text);
if (de == null)
{
MessageBox.Show("帐号无效");
return;
}
string photocol = this.cbbPhotoCol.Text;
System.DirectoryServices.PropertyValueCollection pvc = de.Properties[photocol];
pvc.Value = bb;
de.CommitChanges();
MessageBox.Show("更新成功");
}
2将照片存到AD中
3
4string account = this.tbAccount.Text;
5 if (account == "")
6 {
7 MessageBox.Show("请填写帐号");
8 return;
9 }
string cc = this.textBox1.Text;
if (cc == "")
{
MessageBox.Show("请选择图片");
}
else
{
Image im= Image.FromFile(cc);
MemoryStream Stream = new MemoryStream();
im.Save(Stream, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] bb=Stream.GetBuffer();
DirectoryEntry de = getDirectoryEntryBy(this.tbAccount.Text);
if (de == null)
{
MessageBox.Show("帐号无效");
return;
}
string photocol = this.cbbPhotoCol.Text;
System.DirectoryServices.PropertyValueCollection pvc = de.Properties[photocol];
pvc.Value = bb;
de.CommitChanges();
MessageBox.Show("更新成功");
}
出处:http://www.cnblogs.com/xuanye/archive/2008/05/13/1195225.html