Update document password
GroupDocs.Merger allows to update password from password-protected document. The resultant document will have new password.
Here are the steps to update document password:
- Initialize LoadOptions class specifying current password;
- Instantiate Merger object with source document path or stream and pass LoadOptions object to it;
- Initialize UpdatePasswordOptions class specifying new document password;
- Call UpdatePassword method and pass UpdatePasswordOptions object to it;
- Call Save method specifying file path to save resultant document.
The following code sample demonstrates how to update document password:
string filePath = @"c:\sample.xlsx";
string filePathOut = @"c:\output\result.xlsx";
ILoadOptions loadOptions = new LoadOptions("SAMPLE_PASSWORD");
IUpdatePasswordOptions updateOptions = new UpdatePasswordOptions("NEW_SAMPLE_PASSWORD");
using (Merger merger = new Merger(filePath, loadOptions))
{
merger.UpdatePassword(updateOptions);
merger.Save(filePathOut);
}