Expand my Community achievements bar.

Download policy applied document

Avatar

Level 1

Hello,

  I have created a policy on the server and using the following .NET code, I am trying to download the document once the policy has been applied to:

        Dim rmclient As New RightsManagementService.RightsManagementServiceService

        rmclient.Credentials = New System.Net.NetworkCredential("MyUsername", "MyPassword")

        Dim inDoc As New RightsManagementService.BLOB()
        Dim fs As New FileStream(Server.MapPath("Docs1115.pdf"), FileMode.Open)
        Dim len As Integer = fs.Length()
        Dim byteArray As Byte() = New Byte(len) {}

        fs.Read(byteArray, 0, len)
        inDoc.binaryData = byteArray

        Dim findPolicy As RightsManagementService.PolicySpec = rmclient.getPolicy("DevelopmentPolicySet", "DevelopmentPolicy")

        Dim outBytes As Byte() = rmclient.applyPolicyByPolicyId(inDoc, "Docs1115.pdf", findPolicy.policyId, Nothing, Nothing).binaryData
        Dim fsOut As New FileStream(Server.MapPath("PPDF1_Docs1115.pdf"), FileMode.OpenOrCreate)
        Dim objBinary As New BinaryWriter(fsOut)

        objBinary.Write(outBytes)

        objBinary.Close()
        fs.Close()
        fsOut.Close()

  Due to some reason, I am not able to get BinaryData value from my outDoc and so I cannot create a file out of it. However, when I checked the Admin and Document section, I can see the document there and in the property, I can see that the policy has been applied. I have a link in one of my web page and I want to run the above code and apply policy and also allow user to download the document on click on that.

  How can I download the document with policy applied?

  Any help would be greatly appreciated.

  Thank you,

JD.

0 Replies