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 void SaveUseLicense(
	ContentUser userKey,
	UseLicense useLicense
)
You cannot use methods in XAML.

Parameters

userKey
Type: System.Security.RightsManagement.ContentUser

The user of the UseLicense.

useLicense
Type: System.Security.RightsManagement.UseLicense

The use license to store and embed in the package.

ExceptionCondition
ArgumentNullException

Either the userKey or useLicense parameter is null.

FileFormatException

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. For the full sample, see Rights Managed Package Publish Sample.

WriteStatus("   Signing the UnsignedPublishLicense\n" +
            "       to build the PublishLicense.");
UseLicense authorsUseLicense;
PublishLicense publishLicense =
    unsignedLicense.Sign(_secureEnv, out authorsUseLicense);

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

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

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

ePackage.Close();
WriteStatus("   Done - Package encryption complete.");

WriteStatus("Verifying package encryption.");
if (EncryptedPackageEnvelope.IsEncryptedPackageEnvelope(encryptedFile))
{
    WriteStatus("   Confirmed - '" + encryptedFilename +
                "' is encrypted.");
}
else
{
    MessageBox.Show("ERROR: '" + encryptedFilename +
        "' is NOT ENCRYPTED.", "Encryption Error",
        MessageBoxButton.OK, MessageBoxImage.Error);
    WriteStatus("ERROR: '" + encryptedFilename +
                "' is NOT ENCRYPTED.\n");
    return false;
}

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2015 Microsoft