Working with site policies in SharePoint 2013

  • 1,776 views
Uploaded on

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 …

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.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,776
On Slideshare
0
From Embeds
0
Number of Embeds
7

Actions

Shares
Downloads
35
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 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
  • 2. sponsors
  • 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
  • 7. Information Management Policy Scopes • List • Library • Content Type • Site
  • 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>
  • 11. CREATING AND APPLYING SITE POLICIES IN UI
  • 12. Creating Site Policies in UI
  • 13. Creating Site Policies in UI
  • 14. Creating Site Policies in UI
  • 15. Creating Site Policies in UI
  • 16. Creating Site Policies in UI
  • 17. Applying Site Policies in the UI
  • 18. Applying Site Policies in the UI
  • 19. Applying Site Policies in the UI
  • 20. Applying Site Policies in the UI
  • 21. Site Policies in SSOM namespace Microsoft.Office.RecordsManagement.InformationPolicy { public class ProjectPolicy { public string Description { get; internal set; } public string EmailBody { get; set; } public string EmailBodyWithTeamMailbox { get; set; } public string EmailSubject { get; set; } public string Name { get; internal set; } public public public public public public public public public public public } } static void ApplyProjectPolicy(SPWeb web, ProjectPolicy projectPolicy); static void CloseProject(SPWeb web); static bool DoesProjectHavePolicy(SPWeb web); static ProjectPolicy GetCurrentlyAppliedProjectPolicyOnWeb(SPWeb web); static DateTime GetProjectCloseDate(SPWeb web); static DateTime GetProjectExpirationDate(SPWeb web); static List<ProjectPolicy> GetProjectPolicies(SPWeb web); static bool IsProjectClosed(SPWeb web); static void OpenProject(SPWeb web); static void PostponeProject(SPWeb web); void SavePolicy();
  • 22. SERVER-SIDE OBJECT MODEL DEMOS
  • 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 { } } }
  • 27. Apply Policy private static void ApplyPolicySSOM() { string policyName = "DEVSITE DoNotClose-ReadOnly Policy"; using (SPSite targetSite = new SPSite(siteUrl)) { SPWeb targetWeb = targetSite.RootWeb; List<ProjectPolicy> webPolicies = ProjectPolicy.GetProjectPolicies(targetWeb); ProjectPolicy selectedPolicy = webPolicies.Where(p => p.Name == policyName).FirstOrDefault(); if (selectedPolicy != null) { ProjectPolicy.ApplyProjectPolicy(targetWeb, selectedPolicy); targetWeb.Update(); Console.WriteLine("Successfully applied policy '{0}' on web '{1}'", policyName, targetWeb); } } }
  • 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(); } }
  • 31. CLIENT-SIDE OBJECT MODEL DEMOS
  • 32. Read Site Policies that exist on site private static void ReadProjectPoliciesCsom() { ClientContext policyContext = new ClientContext(siteUrl); Web targetWeb = policyContext.Web; ClientObjectList<ProjectPolicy> projectPolicies = ProjectPolicy.GetProjectPolicies(policyContext, targetWeb); policyContext.Load(projectPolicies); policyContext.ExecuteQuery(); 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(); }
  • 33. Get Applied Policy private static void GetAppliedPolicyCsom() { ClientContext policyContext = new ClientContext(siteUrl); Web targetWeb = policyContext.Web; ClientResult<bool> isPolicyApplied = ProjectPolicy.DoesProjectHavePolicy(policyContext, targetWeb); policyContext.ExecuteQuery(); if (isPolicyApplied.Value) { ProjectPolicy appliedPolicy = ProjectPolicy.GetCurrentlyAppliedProjectPolicyOnWeb(policyContext, targetWeb); policyContext.Load(appliedPolicy); policyContext.ExecuteQuery(); if (appliedPolicy.TypedObject.ServerObjectIsNull != true) { 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(); }
  • 34. Is Policy Applied? private static void IsPolicyAppliedCsom() { ClientContext policyContext = new ClientContext(siteUrl); Web targetWeb = policyContext.Web; ClientResult<bool> isPolicyApplied = ProjectPolicy.DoesProjectHavePolicy(policyContext, targetWeb); policyContext.ExecuteQuery(); if (isPolicyApplied.Value) { Console.WriteLine("Web has policy applied {0}", siteUrl); } else { Console.WriteLine("Project Policy is not applied on web {0}", siteUrl); } Console.WriteLine(); }
  • 35. Apply Policy private static void ApplyPolicyCsom() { string policyName = "DEVSITE DoNotClose-ReadOnly Policy"; ClientContext policyContext = new ClientContext(siteUrl); targetWeb); Web targetWeb = policyContext.Web; ClientObjectCollection<ProjectPolicy> webPolicies = ProjectPolicy.GetProjectPolicies(policyContext, policyContext.Load(webPolicies); policyContext.ExecuteQuery(); ProjectPolicy selectedPolicy = webPolicies.Where(p => p.Name == policyName).FirstOrDefault(); if (selectedPolicy != null) { ProjectPolicy.ApplyProjectPolicy(policyContext, targetWeb, selectedPolicy); policyContext.ExecuteQuery(); Console.WriteLine("Successfully applied policy '{0}' on web '{1}'", policyName, siteUrl); } Console.WriteLine(); }
  • 36. Get Project Close and Expiration Date private static void GetProjectCloseExpirationDateCsom() { ClientContext policyContext = new ClientContext(siteUrl); Web targetWeb = policyContext.Web; ClientResult<DateTime> closedDate = ProjectPolicy.GetProjectCloseDate(policyContext, targetWeb); ClientResult<DateTime> expirationDate = ProjectPolicy.GetProjectExpirationDate(policyContext, targetWeb); policyContext.ExecuteQuery(); if (closedDate.Value != DateTime.MinValue) { Console.WriteLine("Close Date: {0}", closedDate.Value); } if (expirationDate.Value != DateTime.MinValue) { Console.WriteLine("Expiration Date: {0}", expirationDate.Value); } Console.WriteLine(); }
  • 37. Close Site private static void CloseProjectCsom() { ClientContext policyContext = new ClientContext(siteUrl); Web targetWeb = policyContext.Web; ClientResult<bool> isClosed = ProjectPolicy.IsProjectClosed(policyContext, targetWeb); policyContext.ExecuteQuery(); if (!isClosed.Value) { ProjectPolicy.CloseProject(policyContext, targetWeb); } policyContext.ExecuteQuery(); isClosed = ProjectPolicy.IsProjectClosed(policyContext, targetWeb); policyContext.ExecuteQuery(); if (isClosed.Value) { Console.WriteLine("Project is closed! {0}", siteUrl); } else { Console.WriteLine("Project is NOT closed!"); } Console.WriteLine(); }
  • 38. Resources • http://msdn.microsoft.com/enus/library/microsoft.office.recordsmanagement.informationpolicy.proj ectpolicy_members.aspx • http://technet.microsoft.com/en-us/library/jj219569.aspx • http://blog.dragan-panjkov.com/archive/2013/06/30/creating-sitepolicy-in-sharepoint-2013-using-server-code.aspx • http://blog.dragan-panjkov.com/archive/2013/10/27/configuring-sitepolicy-in-sharepoint-2013-using-server-code.aspx • http://blogs.technet.com/b/tothesharepoint/archive/2013/03/28/sitepolicy-in-sharepoint.aspx • http://stevemannspath.blogspot.com/2012/08/sharepoint-2013-siteretention-getting.html • http://www.booden.net/ProjectPolicy.aspx
  • 39. questions? WWW.DRAGAN-PANJKOV.COM @PANJKOV
  • 40. thank you. SHAREPOINT AND PROJECT CONFERENCE ADRIATICS 2013 ZAGREB, NOVEMBER 27-28 2013