RightsManagementInformation.SaveUseLicense Method

Saves a given UseLicense for a specified user to the encrypted rights management data stream.

Namespace:  System.IO.Packaging
Assembly:  WindowsBase (in WindowsBase.dll)

Public Sub SaveUseLicense ( _
	userKey As ContentUser, _
	useLicense As UseLicense _


Type: System.Security.RightsManagement.ContentUser

The user of the UseLicense.

Type: System.Security.RightsManagement.UseLicense

The use license to store and embed in the package.


Either the userKey or useLicense parameter is Nothing.


The rights management information in this package cannot be read by the current version of this class.

After the UseLicense for the specified user has been saved, it can be retrieved through the LoadUseLicense method and from the collection returned by GetEmbeddedUseLicenses.

A Package can store the UseLicense rights information for multiple content users. Each ContentUser can have at most one UseLicense. If SaveUseLicense is called to store a new UseLicense for a ContentUser that already has a UseLicense, the previous license will be overwritten with the new license.

The following example shows how to use of the SaveUseLicense method.

				WriteStatus("   Signing the UnsignedPublishLicense" & vbLf & "       to build the PublishLicense.")
                Dim authorsUseLicense As UseLicense = Nothing
				Dim publishLicense As PublishLicense = unsignedLicense.Sign(_secureEnv, authorsUseLicense)

				WriteStatus("   Binding the author's UseLicense and")
				WriteStatus("       obtaining the CryptoProvider.")
				Dim cryptoProvider As CryptoProvider = authorsUseLicense.Bind(_secureEnv)

				WriteStatus("   Creating the EncryptedPackage.")
				Dim packageStream As Stream = File.OpenRead(packageFile)
				Dim ePackage As EncryptedPackageEnvelope = EncryptedPackageEnvelope.CreateFromPackage(encryptedFile, packageStream, publishLicense, cryptoProvider)

				WriteStatus("   Adding an author's UseLicense.")
				Dim rmi As RightsManagementInformation = ePackage.RightsManagementInformation
				rmi.SaveUseLicense(author, authorsUseLicense)

				WriteStatus("   Done - Package encryption complete.")

				WriteStatus("Verifying package encryption.")
				If EncryptedPackageEnvelope.IsEncryptedPackageEnvelope(encryptedFile) Then
					WriteStatus("   Confirmed - '" & encryptedFilename & "' is encrypted.")
					MessageBox.Show("ERROR: '" & encryptedFilename & "' is NOT ENCRYPTED.", "Encryption Error", MessageBoxButton.OK, MessageBoxImage.Error)
					WriteStatus("ERROR: '" & encryptedFilename & "' is NOT ENCRYPTED." & vbLf)
					Return False
				End If

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft