Search code examples
c#.netpowerpointoffice-interopazure-information-protection

C# MS Office Interop apply Azure Information Protection (AIP)


I need to create PowerPoints but when I’m saving the file (SaveAs method), there is Azure classification add-in which requires manual click (public/internal/confidential) to finish saving the ppt file.

using Microsoft.Office.Interop.PowerPoint;
var pptApplication = new Application();
var pptPresentation = pptApplication.Presentations.Add();
pptPresentation.SaveAs(@"C:\temp\test.pptx", PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue);
pptPresentation.Close();
pptApplication.Quit();

I found online PowerShell method of applying labels but even if it works, it’s done on already existing(saved) file.

Then another find is https://stackoverflow.com/a/57413086/11305428 but I can’t figure out how to apply the label MSIP_Label__Enabled=True

I have the GUID of tags used in my org

strMSIPClassConfidential = "MSIP_Label_-GUID-_Enabled=true;

but haven‘t found how I would apply it to metadata with provided interop. Anyone knows?

Using PowerPoint interop because I haven't found any free libraries for this.


Solution

  • Got it working. If anyone is up to commenting of what the code does feel free to edit.

    void ApplyAIPLabel(Presentation pptPresentation) {
      var customDocumentProperties = pptPresentation.CustomDocumentProperties;
      var typeDocCustomProps = customDocumentProperties.GetType();
      var propertyName = "MSIP_Label_<GUID>_Enabled";
      var propertyValue = "True";
      object[] oArgs = { propertyName, false, MsoDocProperties.msoPropertyTypeString, propertyValue };
      typeDocCustomProps.InvokeMember("Add", BindingFlags.Default | BindingFlags.InvokeMethod, null, customDocumentProperties, oArgs);
    }