Skip to content

Conversation

@jozefizso
Copy link
Member

@jozefizso jozefizso commented Nov 5, 2025

Implements the SensitivyLabel class and related data types.

I used the Plan mode with Claude Sonnet 4.5 to prepare the implementation, and the Agent mode with Claude Haiku 4.5 to implement the changes.

Prompt for plan

Create plan for implementing the SensitivityLabel object model in the Office project.

Object members are documented here: https://learn.microsoft.com/en-us/office/vba/api/office.sensitivitylabel

Include the documentation comments in the generated classes.

@jozefizso jozefizso added this to the 1.9.8 milestone Nov 5, 2025
@jozefizso
Copy link
Member Author

Implementation Plan for SensitivityLabel Object Model

Overview

The SensitivityLabel object provides access to sensitivity label functionality on Office documents. This implementation includes three main components:

  1. SensitivityLabel object - The main wrapper object
  2. LabelInfo object - Data object for label information
  3. MsoAssignmentMethod enum - Enumeration for assignment methods

Files Created

1. DispatchInterfaces/SensitivityLabel.cs

Location: d:\NetOfficeFw\NetOffice\Source\Office\DispatchInterfaces\SensitivityLabel.cs

Structure:

  • Namespace: NetOffice.OfficeApi
  • Base class: _IMsoDispObj
  • Support version: Office 16 (Office 2019+)
  • Entity type: EntityType.IsDispatchInterface

Properties:

  • None (this object only has methods)

Methods:

CreateLabelInfo()

  • Returns: NetOffice.OfficeApi.LabelInfo
  • Parameters: None
  • Description: Creates a new empty LabelInfo object that can be passed to SetLabel method

GetLabel()

  • Returns: NetOffice.OfficeApi.LabelInfo
  • Parameters: None
  • Description: Gets the current label information that exists on the document for the user
  • Note: If the SensitivityLabelPolicy.CompleteInitialize was called, it gets the label for the user that was passed with UserId, otherwise gets the label for the user which is authenticated to the document

SetLabel(LabelInfo, object)

  • Returns: void
  • Parameters:
    • labelInfo (Required) - NetOffice.OfficeApi.LabelInfo - The label information that needs to be set on the document
    • context (Required) - object - A caller-defined context that can be returned with LabelChanged event
  • Description: Sets the label information on the document for the user
  • Note: If the SensitivityLabelPolicy.CompleteInitialize was called, it sets the label for the user that was passed with UserId, otherwise sets the label for the user which is authenticated to the document

Documentation:

/// <summary>
/// DispatchInterface SensitivityLabel 
/// SupportByVersion Office, 16
/// </summary>
/// <remarks> 
/// Represents a wrapper object for accessing sensitivity label on the active document.
/// <para>SensitivityLabel applied on a document requires the use of policy defined by organization administrator. The organization is identified by using an identity of an Office Account signed into Office.</para>
/// <para>Docs: <see href="https://learn.microsoft.com/en-us/office/vba/api/office.sensitivitylabel"/></para>
/// </remarks>

2. DispatchInterfaces/LabelInfo.cs

Location: d:\NetOfficeFw\NetOffice\Source\Office\DispatchInterfaces\LabelInfo.cs

Structure:

  • Namespace: NetOffice.OfficeApi
  • Base class: _IMsoDispObj
  • Support version: Office 16
  • Entity type: EntityType.IsDispatchInterface

Properties (All Read/Write):

Property Type Description
ActionId string Gets or sets the GUID that identifies the action to be performed
AssignmentMethod NetOffice.OfficeApi.Enums.MsoAssignmentMethod Gets or sets how the label was assigned
ContentBits Int32 Gets or sets content markings value
IsEnabled bool Gets or sets whether the label is enabled
Justification string Gets or sets justification text (required when downgrading labels)
LabelId string Gets or sets the GUID of the sensitivity label
LabelName string Gets or sets the display name of the label
SetDate DateTime Gets or sets the date when the label was set
SiteId string Gets or sets the GUID of the SharePoint site

Methods:

  • None (this is a data object with only properties)

Documentation:

/// <summary>
/// DispatchInterface LabelInfo 
/// SupportByVersion Office, 16
/// </summary>
/// <remarks> 
/// Represents the label information data object.
/// <para>The LabelInfo object can be passed to SetLabel method of SensitivityLabel object.</para>
/// <para>Docs: <see href="https://learn.microsoft.com/en-us/office/vba/api/office.labelinfo"/></para>
/// </remarks>

3. Enums/MsoAssignmentMethod.cs

Location: d:\NetOfficeFw\NetOffice\Source\Office\Enums\MsoAssignmentMethod.cs

Structure:

  • Namespace: NetOffice.OfficeApi.Enums
  • Support version: Office 16
  • Entity type: EntityType.IsEnum

Enumeration Values:

Name Value Description
NOT_SET -1 The assignment method value is not set
STANDARD 0 The label is applied by default
PRIVILEGED 1 The label was manually selected
AUTO 2 The label is applied automatically

Documentation:

/// <summary>
/// Indicates the assignment method in a LabelInfo object.
/// </summary>
/// <remarks>
/// <para>MSDN Online Documentation: <see href="https://learn.microsoft.com/en-us/office/vba/api/overview/library-reference/msoassignmentmethod-enumeration-office"/></para>
/// </remarks>

Implementation Details

Standard Patterns Followed

1. Constructor Pattern

All dispatch interface classes follow the standard NetOffice constructor pattern with multiple overloads:

  • Factory + ParentObject + ProxyShare
  • Factory + ParentObject + ComProxy
  • ParentObject + ComProxy
  • Factory + ParentObject + ComProxy + ComProxyType
  • ParentObject + ComProxy + ComProxyType
  • ReplacedObject
  • Default constructor
  • ProgId constructor

2. Property Pattern

[SupportByVersion("Office", 16)]
public string PropertyName
{
    get { return Factory.ExecuteStringPropertyGet(this, "PropertyName"); }
    set { Factory.ExecuteValuePropertySet(this, "PropertyName", value); }
}

3. Method Pattern

[SupportByVersion("Office", 16)]
public ReturnType MethodName(ParameterType param)
{
    return Factory.ExecuteKnownReferenceMethodGet<ReturnType>(this, "MethodName", ReturnType.LateBindingApiWrapperType);
}

4. Enum Pattern

[SupportByVersion("Office", 16)]
EnumValue = NumericValue,

Integration Points

Future Integration Steps

After creating the files, the following integration is needed:

  1. Add to OfficeApi.csproj - Include all three new files in the project file
  2. Host object integration - Add SensitivityLabel property to relevant document objects:
    • Word.Document
    • Excel.Workbook
    • PowerPoint.Presentation
    • Other applicable document types

Testing Considerations

  1. Verify Office 16+ version attribute (SupportByVersion("Office", 16))
  2. Test with documents that have sensitivity labels applied
  3. Validate enum values match COM interface
  4. Ensure proper COM marshaling for all types
  5. Test CreateLabelInfo/GetLabel/SetLabel workflow

Additional Notes

  • The SensitivityLabel object is only available in Office 2019 (version 16) and later
  • Requires specific Microsoft 365 license to access sensitivity label functionality
  • Organization must have sensitivity label policies defined by administrator
  • The organization is identified using an Office Account signed into Office
  • DateTime properties use ExecuteVariantPropertyGet for proper COM marshaling

References


Implementation Status

Completed:

  • SensitivityLabel.cs - All three methods implemented
  • LabelInfo.cs - All nine properties implemented
  • MsoAssignmentMethod.cs - All four enum values implemented
  • All XML documentation added with Microsoft Learn links
  • All compilation errors resolved
  • Follows existing NetOffice architectural patterns

Pending:

  • Add files to OfficeApi.csproj (if not auto-included)
  • Integration with host document objects
  • Unit tests
  • Integration tests with Office 2019+

Implementation completed: November 4-5, 2025
NetOffice Project - SensitivityLabel Object Model

@jozefizso jozefizso self-assigned this Nov 5, 2025
@jozefizso jozefizso linked an issue Nov 5, 2025 that may be closed by this pull request
@DominikPalo DominikPalo self-requested a review November 21, 2025 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SensitivityLabel missing

3 participants