active-directory-photo-toolkit
active-directory-photo-toolkit copied to clipboard
A .NET (C#) library for working with Active Directory to retrieve or set a users thumbnailPhoto.
Active Directory Photo Toolkit 
Installation
Installation is done via NuGet:
Install-Package ActiveDirectoryPhotoToolkit
Usage
Initial setup:
var activeDirectoryPhoto = new ActiveDirectoryPhoto();
Retrieve a users profile photo from Active Directory
var username = "ghuntley";
var format = ActiveDirectoryPhoto.Format.PNG;
var thumbnailPhoto = activeDirectoryPhoto.GetThumbnailPhoto(username, format);
Available formats are available in the ActiveDirectoryPhoto.Format enum.
public enum Format
{
Bmp,
Gif,
Jpg,
Png
};
Saving a retrieved user profile photo to disk in the same folder as the execution, after using the above sample
activeDirectoryPhoto.SaveThumbnailToDisk(thumbnailPhoto);
Saving a retrieved user to a specific folder, after using the retrieve a thumbnail example
activeDirectoryPhoto.SaveThumbnailToDisk(thumbnailPhoto, "C:\\");
Setting a users profile photo
var username = "ghuntley";
var photo = @"C:\photo.jpg";
activeDirectoryPhoto.SetThumbnailPhoto(username, photo);
Removing a users profile photo
var username = "ghuntley";
activeDirectoryPhoto.RemoveThumnnailPhoto(username);
Custom Exceptions
There are two custom exceptions currently which can be caught and handled however you like.
- PhotoResolutionInvalidException - Thrown when the image selected to upload is larger than 200x200px which is the limit set in Active Directory.
- PhotoTooLargeException - Thrown when the image selected is larger than 100kb, again this is a limit set in Acitve Directory.
With thanks to
- The icon "Man" designed by Simple Icons from The Noun Project.
- ghuntley for the initial work
- CaptainQwerty for aditional feature implmenation