Quickstart: List sensitivity labels - Policy SDK (C#)

This quickstart shows you how to use the MIP .NET Policy SDK to list the sensitivity labels configured for your organization.

Prerequisites

If you haven't already, be sure to complete the following prerequisites before continuing:

Add logic to list the sensitivity labels

Add logic to list your organization's sensitivity labels by using the Policy engine object.

  1. Open the Visual Studio solution you created in the previous quickstart.

  2. After the engine loads, add the following code:

    // List sensitivity labels
    Console.WriteLine("\nSensitivity labels for your organization:");
    var labels = engine.ListSensitivityLabels();
    foreach (var label in labels)
    {
        Console.WriteLine($"{label.Name} : {label.Id}");
    
        foreach (var child in label.Children)
        {
            Console.WriteLine($"->  {child.Name} : {child.Id}");
        }
    }
    
  3. Optionally, filter labels by content format:

    // List labels for email content only
    var emailLabels = engine.ListSensitivityLabels(new string[] { "email" });
    

Build and test the application

Build and test your client application.

  1. Use Ctrl+Shift+B (Build Solution) to build the application. If you don't have build errors, use F5 (Start debugging) to run.

  2. On first run, the application prompts for authentication. Provide credentials for a user account in your tenant.

  3. The output displays the sensitivity labels configured for your organization, similar to:

    Sensitivity labels for your organization:
    Public : <label-id>
    General : <label-id>
    ->  Anyone (unrestricted) : <label-id>
    Confidential : <label-id>
    ->  All Employees : <label-id>
    ->  Recipients Only : <label-id>
    Highly Confidential : <label-id>
    ->  All Employees : <label-id>
    ->  Recipients Only : <label-id>
    

Checking label behavior

You can also query label protection type information. Starting in MIP SDK 1.18, the Label class provides properties to check the protection type:

foreach (var label in labels)
{
    Console.Write(label.Name);

    if (label.HasDoNotForwardProtection)
        Console.Write(" [Do Not Forward]");
    else if (label.HasEncryptOnlyProtection)
        Console.Write(" [Encrypt Only]");
    else if (label.HasAdhocProtection)
        Console.Write(" [Custom Protection]");

    Console.WriteLine();
}

Next steps