Write Your Own Rules: Enforcing Your Configuration in SharePoint with Policy Enforcer

One of my favorite products I’ve worked as the architect on this year has been DocAve 6 Administrator. We added the ability to scan farms or monitor audit logs to trigger particular rules. We have 20+ out of the box but the neat part is you can write your own in .NET and hook up to over 37 different trigger events!

I had a customer who wanted to have a rule to enforce that a particular Content Type was always the default on a Document Library within all Sites within a particular Site Collection.

I set up my default “Documents” list in my root site of my site collection to have a new Content Type I created called “Jeremy’s Content Type” and then made it the default:

Policy Enforcer

Content Types

Then in Policy Enforcer I modified my Policy Enforcer Profile that was mapped to that Site Collection to add the “Default Content Type” rule and configured it

Policy Enforcer

Configure Rule

Then I just run the Profile which can also be set up on a schedule.

Policy Enforcer

Run Profile

You’ll see that the Documents library passed with flying colors. You can change the List Settings and run the Profile again to show it failing if you like. I could have extended this rule to only check Libraries that have a particular Document Name using RegEx as an extension of this.

I also wrote the “Action” part of the Policy Enforcer rule. If the rule is set to auto resolve, then it will automatically run this code or if manual, in the Policy Enforcer interface you can click to fix this list. The “Action” part of the code simply sets that Content Type as the default in the list.

The rules are actually very easy to write…all I needed was Visual Studio 2012 and I reference the PolicyEnforcer SDK dll and I added the SharePoint Client dlls. I can debug into my code by fire a debug launcher when I have DocAve, SharePoint and Visual Studio all on the same environment.

Here’s the code block to define the rule:

Image _thumb4

Here’s the code block for the rule validation:

Image _thumb5

Image _thumb6

With 20+ out of the box rules and the ability to write your own, this product is super extensible and unique on the market because of this. For more information check out the Policy Enforcer microsite on the AvePoint web site.

Jeremy was a speaker at the ESPC 2013. Check out Jeremy’s blog for more insightfull content!

Check out Jeremy’s ESPC13 conference presentation on ‘Getting Started with Microsoft Office 365 SharePoint 2013 Online Development‘. Download Now>>

Share this on...

Rate this Post:

Share: