댓글 쓰기 권한이 없습니다. 로그인 하시겠습니까?
C#
2013.08.07 15:07
LDAP Active Directory 계정에서 사진 얻어오기
조회 수 13464 댓글 0
[Solution I] static void InsertPicture(string userName, byte[] data) { using (DirectorySearcher dsSearcher = new DirectorySearcher()) { dsSearcher.Filter = "(&(objectClass=user) (cn=" + userName + "))"; SearchResult result = dsSearcher.FindOne(); using (DirectoryEntry user = new DirectoryEntry(result.Path)) { user.Properties["jpegPhoto"].Clear(); user.Properties["jpegPhoto"].Add(data); user.CommitChanges(); } } } static Image GetUserPicture(string userName) { using (DirectorySearcher dsSearcher = new DirectorySearcher()) { dsSearcher.Filter = "(&(objectClass=user) (cn=" + userName + "))"; SearchResult result = dsSearcher.FindOne(); using (DirectoryEntry user = new DirectoryEntry(result.Path)) { byte[] data = user.Properties["jpegPhoto"].Value as byte[]; if (data != null) { using (MemoryStream s = new MemoryStream(data)) { return Bitmap.FromStream(s); } } return null; } } }
using System; using System.DirectoryServices; using System.Collections; using System.IO; public class ADPhoto { public void Set() { try { var de = new DirectoryEntry("LDAP://cn=username,cn=users,DC=domain, DC=com"); de.Username = "username"; de.Password = "password"; var forceAuth = de.NativeObject; var fs = new FileStream("path\\photo.jpg", FileMode.Open); var br = new BinaryReader(fs); br.BaseStream.Seek(0, SeekOrigin.Begin); byte[] ba = new byte[br.BaseStream.Length]; ba = br.ReadBytes((int)br.BaseStream.Length); de.Properties["jpegPhoto"].Insert(0, ba); de.CommitChanges(); } catch(Exception ex) { Console.WriteLine(ex.Message); } } public Stream Get() { var fs = new MemoryStream(); try { var de = new DirectoryEntry("LDAP://cn=username,cn=users,DC=domain, DC=com"); de.Username = "username"; de.Password = "password"; var forceAuth = de.NativeObject; var wr = new BinaryWriter(fs); byte[] bb = (byte[])de.Properties["jpegPhoto"][0]; wr.Write(bb); wr.Close(); } catch (Exception e) { Console.WriteLine(e.Message); } return fs; } } Dreamy의 코드 스크랩내가 모으고 내가 보는
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Designed by sketchbooks.co.kr / sketchbook5 board skin
Sketchbook5, 스케치북5
Sketchbook5, 스케치북5
Sketchbook5, 스케치북5
Sketchbook5, 스케치북5