kamagra how much to take

How to Forcibly Incorporate a SharePoint Page Layout

One of the principal problems that demonstrates itself when leveraging the SharePoint content deployment API as a replication tool is at some stage page replication tends to cause page layout corruption, indeterminately. Even more disconcerning, the problem is not resolvable through association using the UI following such a corruptible layout action.

That being said, I do not know a direct repair when using particular content deployment objects where this behavior is avoidable, however in this case, it is required instead to approach the repair using some programming approaches. This can, with brief adaptation, be used as an automated repair that can be integrated with custom replication solutions. If you have custom geo-replication, integrating this should be the lowest of your concerns anyways. :)

Now, let’s examine it from the programming standpoint. The main problem that we are trying to solve is if we can hydrate an arbitrary PublishingPage object, how we can build a new PageLayout object in order to forcibly associate the page layout through assignment of the PublishingPage.Layout property.

Firstly, let’s examine some helper methods that we can use in order to solve this problem.

BuildLayoutCollection is going to build an array of PageLayout objects representative of all those available for the current SPWeb (PublishingWeb). ReturnPublishingPage is going to consume the name of the publishing page, and return the argued PublishingPage object. ReturnPageLayout is going to perform a similar function, taking the BuildLayoutCollection method and return the argued PageLayout by specifying its name as a parameter. CreatePublishingWebProxy is going to create the appropriate PublishingWeb object, used as a sister method.

  1. private PageLayout[] BuildLayoutCollection()
  2. {
  3. PublishingWeb pubWeb = CreatePublishingWebProxy();
  4. return pubWeb.GetAvailablePageLayouts();
  5. }private PublishingPage ReturnPublishingPage(string pageName)
  6. {
  7. PublishingWeb pubWeb = CreatePublishingWebProxy();
  8. PublishingPageCollection pages = pubWeb.GetPublishingPages();
  9. foreach (PublishingPage page in pages)
  10. {
  11. if (Equals(page.Name, pageName))
  12. {
  13. return page;
  14. }
  15. }
  16. return null;
  17. }
  18.  
  19. private PageLayout ReturnPageLayout(string layoutName)
  20. {
  21. PageLayout[] layouts = BuildLayoutCollection();
  22. foreach (PageLayout layout in layouts)
  23. {
  24. if (Equals(layout.Name, layoutName))
  25. {
  26. return layout;
  27. }
  28. }
  29. return null;
  30. }
  31.  
  32. private PublishingWeb CreatePublishingWebProxy()
  33. {
  34. using (SPSite site = new SPSite(Url))
  35. {
  36. using (SPWeb web = site.OpenWeb())
  37. {
  38. return PublishingWeb.GetPublishingWeb(web);
  39. }
  40. }
  41. }

Following, we can use these methods in order to execute our assimilation of publishing pages as such (notice that the page is being checked out, updated, and then checked in):

  1. PublishingPage page = ReturnPublishingPage(pageName);
  2. PageLayout layout = ReturnPageLayout(layoutName);
  3. page.CheckOut();
  4. page.Layout = layout;
  5. page.Update();
  6. page.CheckIn("Page Modified For Layout Assimilation");

Following, your association should be good to go! :)

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>