共用方式為


How to delete a user from BDC permissions list

Once one my colleagues had a requirement where he want to delete users from ‘Business Data Catalogue Permissions’ programmatically.

Here are the few classes that you can use to deal with the BDC permissions programmatically:

Namespace: Microsoft.Office.Server.ApplicationRegistry.Infrastructure (Microsoft.SharePoint.Portal.dll contains the above namespace)

Classes:

1. BdcAccessControlList

2. IndividualAccessControlEntry

My colleague Varun has written a post about how to add a user to the BDC permission list through code, please take a look at his post for getting the complete snippet here.

Here I am giving the code snippet for deleting the users; however like adding the user we don’t have direct method to delete the user instead we need to do a little tweak.

    1: using System;
    2: using System.Collections.Generic;
    3: using System.Linq;
    4: using System.Text;
    5:  
    6: using Microsoft.Office.Server.ApplicationRegistry.Administration;
    7: using Microsoft.Office.Server.ApplicationRegistry.Infrastructure;
    8:  
    9: namespace RemoveUSER
   10: {
   11:     class Program
   12:     {
   13:         static void Main(string[] args)
   14:         {
   15:             SqlSessionProvider.Instance().SetSharedResourceProviderToUse("SharedServices1");
   16:             
   17:             try
   18:             {
   19:                 ApplicationRegistry registry = ApplicationRegistry.Instance;
   20:                 IAccessControlList acl = registry.GetAccessControlList();
   21:                 IAccessControlList acl2 = acl.Clone();
   22:                 acl.Clear();
   23:                 foreach (IAccessControlEntry entry in acl2)
   24:                 {
   25:                     if (entry.IdentityName.Equals("BLRS2R04-08\\Administrator"))
   26:                     {
   27:                         
   28:                     }
   29:                     else
   30:                     {
   31:                         acl.Add(entry);
   32:                     }
   33:                 }                
   34:                 registry.SetAccessControlList(acl);
   35:             }
   36:             catch (Exception ex)
   37:             {
   38:             }
   39:  
   40:         }
   41:     }
   42: }