Version

SetFileWriteProtectionPassword(String,String) Method

Sets the password used to protect the file from automatic writes.
Syntax
'Declaration
 
Public Overloads Sub SetFileWriteProtectionPassword( _
   ByVal password As System.String, _
   Optional ByVal userName As System.String _
) 
public void SetFileWriteProtectionPassword( 
   System.string password,
   System.string userName
)

Parameters

password
The password to use to protect the file; null or the empty string will remove write protection from the file.
userName
The name of the user to store as the FileWriteProtectedBy value. If null is specified and a valid password is specified, the Environment.UserName will be used instead (on all platforms except for Silverlight and WinRT).
Remarks

If the userName is specified but the password is being clear because it is being set to null or empty, the user name is ignored and FileWriteProtectedBy is set to null.

Note: The Workbook and its related sub-objects do not prevent modifications at runtime when a file is write protected, as Microsoft Excel allows UI modifications to write protected files which are not unlocked with the proper password. In addition, write protected Workbook instances do not prevent saves to the file location from which they were loaded, as it is possible to overwrite files in this situation in Microsoft Excel via the 'Save As' dialog. It is the responsibility of the Workbook's consumer to prevent automatic file overwrites when IsFileWriteProtected is true.

Requirements

Target Platforms: Windows 8.1, Windows 8.1, Windows 8, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

View on GitHub