Wednesday, December 10, 2014

Assign broken permissions to publishing pages through programtically

PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(newSite);
                                            PublishingPageCollection allPages = publishingWeb.GetPublishingPages();
 
                                            foreach (PublishingPage page in allPages)
                                            {
                                                Console.WriteLine(page.Name);
 
                                                if (page.Name.ToLower() == "about us.aspx" || page.Name.ToLower() == "people.aspx" || page.Name.ToLower() == "services.aspx")
                                                {
                                                    #region checkout and assign the permissions to intranet_readers
 
                                                    // checkout the page
                                                    if (page.ListItem.File.CheckOutType == SPFile.SPCheckOutType.None)
                                                    {
                                                        page.CheckOut();
                                                    }
                                                    else
                                                    {
                                                        page.ListItem.File.UndoCheckOut();
                                                        page.CheckOut();
                                                    }
 
                                                    // Break the permissions
                                                    page.ListItem.BreakRoleInheritance(true);
 
                                                    // Rename the page
                                                    //page.ListItem["Name"] = "About us";
 
                                                    // Assign the permissions to intranet_readers
                                                    SPRoleAssignment roleAssignment = new SPRoleAssignment(newSite.SiteGroups["readersgroup"]);
                                                    if (roleAssignment != null)
                                                    {
                                                        roleAssignment.RoleDefinitionBindings.Add(newSite.RoleDefinitions["Read"]);
                                                        page.ListItem.RoleAssignments.Add(roleAssignment);
                                                        page.ListItem.Update();
                                                    }
                                                    // CheckIn the page
                                                    page.CheckIn("Broken permissions added");
                                                    // publish the page
                                                    SPModerationInformation moderationInformation = page.ListItem.ModerationInformation;
 
                                                    if (moderationInformation != null && moderationInformation.Status != SPModerationStatusType.Approved)
                                                    {
                                                        SPFile pageFile = page.ListItem.File;
                                                        pageFile.Publish("publish comments");
                                                        pageFile.Approve("approve comments");
                                                    }
 
                                                    #endregion
                                                }
 
                                            }

No comments:

Post a Comment

Image noise comparison methods

 1. using reference image technique     - peak_signal_noise_ratio (PSNR)     - SSI 2. non-reference image technique     - BRISQUE python pac...