如何从Outlook里获得用户的名字和头像
2012-06-25 16:51
316 查看
今天share一下如何从outlook里获得缩略图和全名的两个方法。方法的难点是如何从SearchResult 里获得想要的信息。因为这个结果里有大量信息。目前我还没有找到一个很好的方法来处理。找到后我会补全这块的信息。方法仅供参考。
private static string GetThumnailImage(string domain, string alias) { Bitmap thumnailImage = null; DirectorySearcher dirSearcher = new DirectorySearcher(); DirectoryEntry rootEntry = new DirectoryEntry("LDAP://fareast.corp.microsoft.com"); dirSearcher.SearchRoot = rootEntry; dirSearcher.Filter = string.Format("(|(sAMAccountName={0})(cn={0}))", alias); dirSearcher.SearchScope = SearchScope.Subtree; SearchResultCollection searchResultColl = dirSearcher.FindAll(); string imagePath = AppDomain.CurrentDomain.BaseDirectory + "thumbnailphoto.png"; if (searchResultColl.Count <= 0) { throw new System.Security.Authentication.AuthenticationException(); } SearchResult result = searchResultColl[0]; if (result == null || result.Properties == null) { throw new System.Security.Authentication.AuthenticationException(); } if (result.Properties["thumbnailphoto"] != null && result.Properties["thumbnailphoto"].Count > 0) { byte[] imageBytes = new byte[((byte[])result.Properties["thumbnailphoto"][0]).Count<byte>()]; Array.Copy((byte[])result.Properties["thumbnailphoto"][0], imageBytes, imageBytes.Count<byte>()); using (System.IO.MemoryStream mmStream = new System.IO.MemoryStream(imageBytes)) { thumnailImage = new System.Drawing.Bitmap(mmStream); mmStream.Flush(); thumnailImage.Save(imagePath); } } return imagePath; } private static string GetFullName(string domain, string alias) { DirectorySearcher dirSearcher = new DirectorySearcher(); DirectoryEntry rootEntry = new DirectoryEntry("LDAP://fareast.corp.microsoft.com"); dirSearcher.SearchRoot = rootEntry; dirSearcher.Filter = string.Format("(|(sAMAccountName={0})(cn={0}))", alias); dirSearcher.SearchScope = SearchScope.Subtree; SearchResultCollection searchResultColl = dirSearcher.FindAll(); string name = string.Empty; if (searchResultColl.Count <= 0) { throw new System.Security.Authentication.AuthenticationException(); } SearchResult result = searchResultColl[0]; if (result == null || result.Properties == null) { throw new System.Security.Authentication.AuthenticationException(); } if (result.Properties["givenname"] != null && result.Properties["givenname"].Count > 0) { name = result.Properties["givenname"][0].ToString(); } if (result.Properties["sn"] != null && result.Properties["sn"].Count > 0) { name += " " + result.Properties["sn"][0].ToString(); } return name; }
相关文章推荐
- wordpress如何获得当前用户的头像
- linux下如何添加一个用户并且让用户获得root权限
- 如何获得数据库里所有表的名字(SQL+C#)
- 如何获得用户密码被修改的天数
- c#获得本机计算机名字,获得本机当前系统登陆用户和管理员权限,Environment
- 如何获得数据库里所有表的名字 推荐
- linux下如何添加一个用户并且让用户获得root权限
- (第3讲)Java如何获得用户在控制台输入的东西(Scanner和BufferedReader的区别)
- 如何获得超级用户的管理权限
- 如何阻止通过Outlook用户发送WORD或EXCEL变成带Winmail.dat文件附件的邮件
- 如何获得数据库里所有表的名字(SQL+C#) (转)收藏。。。
- HTML提交表单用户选择的头像如何利用<select>标签提交到PHP并连接数据库进行存读操作
- Linux 如何添加一个用户并且让用户获得root权限
- 想用二维码推广应用,如何保证 Andriod 用户和 iOS 用户扫描同一个二维码后获得相应的 App ?
- 小程序如何快速获得3000用户?
- 如何通过窗口名字获得窗口对象
- iOS 开发 如何获得用户当前位置(通过经纬度获得城市、省份等信息)
- 新用户如何获得阿里云优惠怎么才能省钱-写给阿里云新手
- 如何通过ADO获得Access数据库中的所有用户表和表信息
- linux下如何添加一个用户并且让用户获得root权限