Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

GetPolicies Method

SQL Server 2000

ReportingService.GetPolicies Method

Returns the policies that are associated with a particular item in the report server database.

Public Function GetPolicies( _
   ByVal Item As String, _
   ByRef InheritParent As Boolean _
) As [Namespace].Policy[]
   Member of [Namespace].ReportingService
public [Namespace].Policy[] GetPolicies(
   string Item,
   out bool InheritParent
);
   Member of [Namespace].ReportingService
Parameters
Item
The full path name of the item.
InheritParent
A Boolean expression that indicates whether the item inherits policies from its parent.
Return Value

An array of Policy[] objects that contains the users and roles associated with the item.

Permissions

Operation Description
Read Security Policies Required to read the security policies that are set on an item.

Example

To compile this code example, you must reference the Reporting Services WSDL and import certain namespaces. For more information, see Compiling and Running Code Examples. The following code example uses the GetPolicies method to discover whether an item is provided a custom role assignment or whether the role assignment is inherited from a parent item. If the role assignment is inherited, the code example traverses up the folder hierarchy of the report server database to determine from which parent item the role assignment is inherited. The ListChildren method is used to retrieve the initial item list from the report server database. The GetParentPath method of the code example is used to parse the string path of any report server item and return the path of the parent item:

Imports System
Imports System.Web.Services.Protocols
Imports System.Text.RegularExpressions

Class Sample
    Public Shared Sub Main()
      Dim rs As New ReportingService()
      rs.Credentials = System.Net.CredentialCache.DefaultCredentials

      Try
         Dim inheritParent As Boolean
         Dim rolePath As String
         Dim items As CatalogItem() = rs.ListChildren("/", True)
         Dim item As CatalogItem
         For Each item In  items
            rolePath = item.Path
            rs.GetPolicies(rolePath, inheritParent)
            While inheritParent
               rolePath = GetParentPath(rolePath)
               rs.GetPolicies(rolePath, inheritParent)
            End While
            If item.Path = rolePath Then
               Console.WriteLine("The item {0} does not inherit it's role assignment.", item.Path)
            Else
               Console.WriteLine("The item {0} inherits it's role assignment from {1}", item.Path, rolePath)
            End If
         Next item
      
      Catch e As SoapException
         Console.WriteLine(e.Detail("Message").InnerXml)
      
      Catch e As Exception
         Console.WriteLine(e.Message)
      End Try
   End Sub 'Main

   Private Shared Function GetParentPath(currentPath As String) As String
      Dim delimiter As String = "/"
      Dim rx As New Regex(delimiter)
      Dim childPath As String() = rx.Split(currentPath)
      
      Dim parentLength As Integer = childPath.Length - 1
      Dim parentPath(parentLength) As String
      
      Dim i As Integer
      For i = 0 To parentLength - 1
         parentPath(i) = childPath(i)
      Next i 
      If parentPath.Length = 1 Then
         Return "/"
      Else
         Return String.Join("/", parentPath)
      End If
   End Function 'GetParentPath
End Class 'Sample
using System;
using System.Web.Services.Protocols;
using System.Text.RegularExpressions;

class Sample
{
   public static void Main()
   {
      ReportingService rs = new ReportingService();
      rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
      
      try
      {
         bool inheritParent;
         string rolePath;
         CatalogItem[] items = rs.ListChildren("/", true);
         foreach (CatalogItem item in items)
         {
            rolePath = item.Path;
            rs.GetPolicies(rolePath, out inheritParent);
            while (inheritParent)
            {
               rolePath = GetParentPath(rolePath);
               rs.GetPolicies(rolePath, out inheritParent);
            }
            if (item.Path == rolePath)
               Console.WriteLine("The item {0} does not inherit it's role assignment.", item.Path);
            else
               Console.WriteLine("The item {0} inherits it's role assignment from {1}",
                  item.Path, rolePath);
         }
      }

      catch (SoapException e)
      {
         Console.WriteLine(e.Detail["Message"].InnerXml); 
      }

      catch (Exception e)
      {
         Console.WriteLine(e.Message);
      }
   }

   private static string GetParentPath(string currentPath)
   {
      string delimiter = "/";
      Regex rx = new Regex( delimiter );
      string[] childPath = rx.Split( currentPath );
       
      int parentLength = childPath.Length - 1;
      string[] parentPath = new string[parentLength];
      
      for ( int i = 0; i < parentLength; i++ )
         parentPath[i] = childPath[i];
 
      if ( parentPath.Length == 1 )
         return "/";
      else
         return String.Join( "/", parentPath );
   }
}
See Also

ReportingService Class

Reporting Services Web Service Library

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.