Microsoft Purview and Word documents

Hello,
we are currently investigating the support of Microsoft Purview sensitivity labels in Word documents.
Question: Is it possible to read and set the sensitivity label in a Word document with the help of Aspose.Words for Java?
Best regards
Matthias

@curmas

Hello Matthias,

Yes, you can store Microsoft Purview sensitivity labels in Word documents using Aspose.Words for Java. To achieve this, you need to set the document properties to include the sensitivity label. Here’s a basic example of how to do this:

import com.aspose.words.Document;
import com.aspose.words.DocumentBuilder;

public class SensitivityLabelExample {
    public static void main(String[] args) throws Exception {
        // Load your document
        Document doc = new Document("input.docx");
        
        // Set the sensitivity label
        doc.getBuiltInDocumentProperties().setProperty("SensitivityLabel", "YourSensitivityLabel");

        // Save the document
        doc.save("output.docx");
    }
}

In this example, replace "YourSensitivityLabel" with the actual label you want to apply. This will embed the sensitivity label into the document properties, which can then be recognized by Microsoft Purview.

To proceed, ensure you have the Aspose.Words library included in your project. If you have any further questions or need assistance with implementation, please let me know, and I’ll be happy to help!

Thanks for your answer.
I guess, reading the sensitivity label is done the same way - simply reading the document property?
Another question: This feature is available for Excel or other Office files too?
Kind regards
Matthias

@curmas Aspose.Words does not support loading documents marked with sensitivity labels. There is an article that explains how to work with such documents in .NET:
https://docs.aspose.com/words/net/work-with-document-market-by-sensitivity-label/

Hello Alexey,

thanks for your answer.

I can not find any method called setProperty for BuiltInDocumentProperties in Java
doc.getBuiltInDocumentProperties().setProperty(“SensitivityLabel”, “YourSensitivityLabel”);
Do you know an alternative?

Another question:
If loading documents marked with sensitivity labels is not possible, converting to PDF is not possible too. Is that correct?

Kind regards
Matthias

@curmas

There is no built-in property called SensitivityLabel in MS Word documents. Probably you can use custom document properties:

doc.getCustomDocumentProperties().add("SensitivityLabel", "YourSensitivityLabel");

Yes, you are absolutely right.

Hi Alexey,
thanks for your super fast response.
Since the first message comes from your chatbot, I would like to ask again to be on the safe side.
We are currently investigating the support of Microsoft Purview sensitivity labels in Word documents.
We can set the sensitivity label in word documents by sinply setting a custom document property named “SensitivityLabel”? Is that correct?

Question: Can we do this for other office document variants too? for example MS Excel, MS Powerpoint…

Best regards
Matthias

@curmas

No, this is not correct. The bot’s answer is not quite correct.

The save applies to other office documents. Sensitivity label is not just property in the document.

Hi @alexey.noskov,

ok :slight_smile:
How can we set the sensitivity label for Microsoft PureView in office documents using Aspose for Java. Do you have an example or link?

Best regards
Matthias

@curmas As I have mentioned Aspose.Words does not support loading documents marked with sensitivity labels. Also Aspose.Words does not support making documents with sensitivity labels. So unfortunately, there is no way to achieve this using Aspose.Words.

Hi @alexey.noskov,

ok, now i know the facts. Thanks for your answer.

Best regards
Matthias

1 Like