How to Save Sensitivity-Labeled Files with the Same Name via MIP SDK
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.

- 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.
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.
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.
Initialize the MIP SDK file handler and pass the source file path to read its current sensitivity label.
Set the new label using the SetLabel method on the file handler.
Commit the changes and direct the output stream to a new, temporary file path within the same directory or a safe temp folder.
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.

Consult Microsoft Q&A for Office Development
For advanced or highly customized Office add-in scenarios, engaging with official developer support will yield the most accurate SDK-specific guidance.
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. Download the software: Visit the WPS Office website and download the free installation package for your operating system.
- 2. Install WPS Office: Run the installer and follow the on-screen prompts to set up WPS Office on your device.
- 3. Open your files: Double-click your existing Office documents to seamlessly open and edit them in 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.




