Skip to content

A .NET (C#) library for working with Active Directory to retrieve or set a users thumbnailPhoto.

License

Notifications You must be signed in to change notification settings

captainqwerty/active-directory-photo-toolkit

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Icon

Active Directory Photo Toolkit Build status

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

About

A .NET (C#) library for working with Active Directory to retrieve or set a users thumbnailPhoto.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 93.9%
  • PowerShell 6.1%