Session slides from SharePoint and Project Conference Adriatics 2013. Similar to lists and content types in previous SharePoint versions, with SharePoint 2013 it is possible to set and enforce retention rules to entire SharePoint site collections. In this session we will describe what are site retention policies, what we need to set up in order to be able to define and apply site retention policies, and how to work with site retention from code.
1. Working with site policies in
SharePoint 2013
DRAGAN PANJKOV, PLANB.
B: WWW.DRAGAN-PANJKOV.COM
T: @PANJKOV
SHAREPOINT AND PROJECT CONFERENCE ADRIATICS 2013
ZAGREB, NOVEMBER 27-28 2013
3. About
• Dragan Panjkov
• Working with SharePoint since 2007
• www.dragan-panjkov.com
• www.twitter.com/panjkov
• PlanB. d.o.o.
• www.planb.ba
• SharePoint user group
• www.1sug.com
4. Agenda
• Information Management Policies
• Site Policies
• Configuration steps needed to enable Site Policies on sites
• Creating Site Policies in SharePoint UI
• Working with Site Policies using Server OM
• Working with Site Policies using Client OM
5. Information management policy?
• An information management policy is a set of rules that govern
the availability and behavior of a certain type of important
content. Policy enables administrators to control and
evaluate who can access information, how long to retain
information, and how effectively people are complying with the
policy.
6. In other words
• Information Management Policy connects business need and
technical implementation of the solution to ensure that
standards are met
Business
Outcomes
Information
Classification
Functional
Preferences
Information
Architecture
Functional
Design
Information
Management
Standards
Information
Management
Policies
Information
Management
Architecture
Technical
Considerations
Service
Management
Policies
Service
Architecture
Project Constraints
Budget, Timeframe, Resources
8. Site Retention?
• How do we control site lifecycle?
• Are we able to track old and unused sites?
• Are we able to easily delete old, unused, expired sites?
9. Site Policies
• Opportunity to predefine retention rules for sites
• Assign retention policy at site creation
• Site Policies can be configured that sites are:
• Closed and then deleted automatically
• Deleted automatically after certain period of time
• Marked as read-only
• Site Policies can be published in Content Type Hub
10. Enabling Site Policy functionality
In UI:
• Enable features in Site Collection
• Library and Folder Based Retention
• Site Policy
• Hidden feature “Record Resources” activated automatically
In onet.xml
<SiteFeatures>
<Feature ID="5bccb9a4-b903-4fd1-8620-b795fa33c9ba" Name="RecordResources" />
<Feature ID="063c26fa-3ccc-4180-8a84-b6f98e991df3" Name="LocationBasedPolicy" />
<Feature ID="2fcd5f8a-26b7-4a6a-9755-918566dba90a" Name="ProjectBasedPolicy" />
</SiteFeatures>
23. Create Site Policies
// ProjectPolicy Content Type ID
SPContentTypeId policyCTID= new SPContentTypeId("0x010085EC78BE64F9478aAE3ED069093B9963");
SPContentTypeCollection contentTypes = site.RootWeb.ContentTypes;
// ProjectPolicy is parent content type
SPContentType parentContentType = contentTypes[policyCTID];
// we create new content type based on ProjectPolicy
policyContentType = new SPContentType(parentContentType, contentTypes, "New Project Policy");
policyContentType = contentTypes.Add(policyContentType);
policyContentType.Group = parentContentType.Group;
policyContentType.Hidden = true;
policyContentType.Update();
// Final step is to create new Policy with new content type
Policy.CreatePolicy(policyContentType, null);
24. Read Site Policies that exist on site
private static void ReadProjectPolicies()
{
using (SPSite targetSite = new SPSite(siteUrl))
{
SPWeb targetWeb = targetSite.RootWeb;
List<ProjectPolicy> projectPolicies = ProjectPolicy.GetProjectPolicies(targetWeb);
if (projectPolicies!= null && projectPolicies.Count > 0)
{
Console.WriteLine("Project Policies on web {0}", siteUrl);
foreach (var item in projectPolicies)
{
Console.WriteLine("Name: {0}",item.Name);
Console.WriteLine("Desc: {0}",item.Description);
Console.WriteLine();
}
}
Console.WriteLine();
try
{
targetWeb.Dispose();
}
catch { }
}
}
25. Get Applied Policy
private static void GetAppliedPolicy()
{
using (SPSite targetSite = new SPSite(siteUrl))
{
SPWeb targetWeb = targetSite.RootWeb;
ProjectPolicy appliedPolicy = ProjectPolicy.GetCurrentlyAppliedProjectPolicyOnWeb(targetWeb);
if (appliedPolicy != null)
{
Console.WriteLine("Currently applied Project Policy on web {0}", siteUrl);
Console.WriteLine(appliedPolicy.Name);
Console.WriteLine(appliedPolicy.Description);
}
else
{
Console.WriteLine("Project Policy is not applied on web {0}", siteUrl);
}
Console.WriteLine();
try
{
targetWeb.Dispose();
}
catch { }
}
}
26. Is Policy Applied?
private static void IsPolicyApplied()
{
using (SPSite targetSite = new SPSite(siteUrl))
{
SPWeb targetWeb = targetSite.RootWeb;
bool isPolicyApplied = ProjectPolicy.DoesProjectHavePolicy(targetWeb);
if (isPolicyApplied)
{
Console.WriteLine("Web has policy applied {0}", siteUrl);
}
else
{
Console.WriteLine("Project Policy is not applied on web {0}", siteUrl);
}
Console.WriteLine();
try
{
targetWeb.Dispose();
}
catch { }
}
}
28. Get Project Close and Expiration Date
private static void GetProjectCloseExpirationDate()
{
using (SPSite targetSite = new SPSite(siteUrl))
{
SPWeb targetWeb = targetSite.RootWeb;
DateTime closedDate = ProjectPolicy.GetProjectCloseDate(targetWeb);
DateTime expirationDate = ProjectPolicy.GetProjectExpirationDate(targetWeb);
if (closedDate != DateTime.MinValue)
{
Console.WriteLine("Close Date: {0}", closedDate);
}
if (expirationDate != DateTime.MinValue)
{
Console.WriteLine("Expiration Date: {0}", expirationDate);
}
Console.WriteLine();
try
{
targetWeb.Dispose();
}
catch { }
}
}
29. Open Closed Site ELEVATED
private static void OpenProject()
{
using (SPSite site = new SPSite(siteUrl))
{
SPSecurity.RunWithElevatedPrivileges(delegate
{
using (SPSite targetSite = new SPSite(siteUrl))
{
SPWeb targetWeb = targetSite.RootWeb;
bool isClosed = ProjectPolicy.IsProjectClosed(targetWeb);
Console.WriteLine("Site is Closed! {0}", siteUrl);
if (isClosed)
{
Console.WriteLine("Trying to open site.");
ProjectPolicy.OpenProject(targetWeb);
Console.WriteLine("Site is now Open! {0}", siteUrl);
}
Console.WriteLine();
try
{
targetWeb.Dispose();
}
catch { }
}
});
}
}
30. Site Policies in CSOM
namespace Microsoft.SharePoint.Client.InformationPolicy
{
[ScriptType("SP.InformationPolicy.ProjectPolicy", ServerTypeId = "{ec5e0a70-0cc3-408f-a4dc-1bb3495aac75}")]
public class ProjectPolicy : ClientObject
{
[EditorBrowsable(EditorBrowsableState.Never)]
public ProjectPolicy(ClientRuntimeContext context, ObjectPath objectPath);
[Remote]
public static void ApplyProjectPolicy(ClientRuntimeContext context, Web web, ProjectPolicy projectPolicy);
[Remote]
public static void CloseProject(ClientRuntimeContext context, Web web);
[Remote]
public static ClientResult<bool> DoesProjectHavePolicy(ClientRuntimeContext context, Web web);
[Remote]
public static ProjectPolicy GetCurrentlyAppliedProjectPolicyOnWeb(ClientRuntimeContext context, Web web);
[Remote]
public static ClientResult<DateTime> GetProjectCloseDate(ClientRuntimeContext context, Web web);
[Remote]
public static ClientResult<DateTime> GetProjectExpirationDate(ClientRuntimeContext context, Web web);
[Remote]
public static ClientObjectList<ProjectPolicy> GetProjectPolicies(ClientRuntimeContext context, Web web);
protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader);
[Remote]
public static ClientResult<bool> IsProjectClosed(ClientRuntimeContext context, Web web);
[Remote]
public static void OpenProject(ClientRuntimeContext context, Web web);
[Remote]
public static void PostponeProject(ClientRuntimeContext context, Web web);
[Remote]
public void SavePolicy();
}
}