2

I know the name of the layout page. Do I still have to go through this process to get the layout page?

foreach (PageLayout pl in pageLayouts)
{
if (pl.Name.Equals("MyLayout.aspx", StringComparison.InvariantCultureIgnoreCase))
  {
    currPageLayout = pl;
  }
}
2

1 Answer 1

2

Since a PageLayout is just an SPFile in an SPList (Master Page Gallery), you can get a reference to the SPFile and use the PageLayout constructor to get your PageLayout by passing in SPFile.Item

Something like this

new PageLayout(site.RootWeb.Files["webrelativeurltoyourpagelayout.aspx"].Item);
3
  • that did not work. hmm. any other suggesion(s)? May 18, 2011 at 17:16
  • Did you manage to get a valid reference to the SPFile? What value did you use for webrelativeurltoyourpagelayout.aspx? May 24, 2011 at 13:14
  • this worked for me: new PageLayout(site.RootWeb.GetFile("_catalogs/masterpage/newLayout.aspx").Item);
    – Chloraphil
    Feb 7, 2013 at 0:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.