如何从Outlook里获得用户的名字和头像
今天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;}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
