Others

How to Save Sensitivity-Labeled Files with the Same Name via MIP SDK

Huda QurayshiHuda Qurayshi Nov 4, 2026 869 views

Question details

The user needs to modify a file's sensitivity label via an Office add-in using the MIP SDK and save the file in place, rather than outputting it to a new name or path.

Saving a Sensitivity-Labeled File with the Same Name using MIP SDK
Product
Microsoft Office / MIP SDK
Device & OS
not provided
Scenario
Programmatically reading and changing document sensitivity labels through a customized Office add-in using the Microsoft Information Protection SDK.
Observed behavior
The current SDK implementation outputs the newly labeled file to a different name or path instead of overwriting the original file directly.
Before you start

Ensure you are using the latest version of the Microsoft Information Protection (MIP) SDK and back up your testing directories before implementing automated file overwrite operations.

Solution 1Recommended

Implement a Temporary File Replacement Workaround

Because the MIP SDK requires writing to a separate output stream to prevent file corruption, you can achieve an in-place save by outputting to a temporary file and replacing the original.

The MIP SDK File API typically reads from an input stream and writes to an output stream. Attempting to write directly to the source file while it is being read can cause access violations or data loss. A standard development practice is to use a temporary file.

1
Read the original file

Initialize the MIP SDK file handler and pass the source file path to read its current sensitivity label.

2
Apply the new sensitivity label

Set the new label using the SetLabel method on the file handler.

3
Output to a temporary path

Commit the changes and direct the output stream to a new, temporary file path within the same directory or a safe temp folder.

4
Replace the original file

Once the commit is fully successful and the stream is closed, delete the original file and rename the temporary file to match the original file name.

Implement a Temporary File Replacement Workaround
Handling File Permissions: Ensure your add-in or application has sufficient system permissions to delete and rename files in the target directory.
Free Microsoft Office alternative

Try WPS Office for a Lightweight Document Experience

If you are managing everyday documents and looking for a fast, free, and highly compatible alternative to Microsoft Office without complex enterprise add-in dependencies, WPS Office is an excellent choice.

  1. 1. Download the software: Visit the WPS Office website and download the free installation package for your operating system.
  2. 2. Install WPS Office: Run the installer and follow the on-screen prompts to set up WPS Office on your device.
  3. 3. Open your files: Double-click your existing Office documents to seamlessly open and edit them in WPS Office.
Free and lightweight alternative to Microsoft OfficeFully compatible with Microsoft Word (.docx), Excel (.xlsx), and PowerPoint (.pptx) formatsFamiliar user interface for immediate productivity without a learning curveBuilt-in PDF editor and powerful document management tools
microsoft office alternative - wps office

Frequently Asked Questions

Why does the MIP SDK require saving to a new file stream?

The MIP SDK handles document encryption and metadata tagging by generating a new stream. This is a protective measure to ensure the original file is not corrupted if the labeling process fails or is interrupted midway.

Can I remove a sensitivity label programmatically using the MIP SDK?

Yes, you can use the MIP SDK's FileHandler to programmatically delete a sensitivity label. However, if the label policy requires justification for downgrading or removing a label, your code must supply that justification during the removal process.

What happens if a user tries to open a labeled document in an unsupported application?

If the sensitivity label applies encryption (RMS), opening the document in an application that does not support MIP or cannot authenticate the user will result in an error or display a wrapper indicating the file is protected.