Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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;
  }
}
share|improve this question
    
I guess if I know the content type id then it can be. tonstegeman.com/Blog/Lists/Posts/… PageLayout[] layouts = publishingWeb.GetAvailablePageLayouts(contentType.Id); –  Monica Contera May 12 '11 at 13:58
    
what is your variable pageLayouts? –  Abe Miessler May 12 '11 at 15:22

1 Answer 1

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);
share|improve this answer
    
that did not work. hmm. any other suggesion(s)? –  Monica Contera May 18 '11 at 17:16
    
Did you manage to get a valid reference to the SPFile? What value did you use for webrelativeurltoyourpagelayout.aspx? –  Jaap Vossers May 24 '11 at 13:14
    
this worked for me: new PageLayout(site.RootWeb.GetFile("_catalogs/masterpage/newLayout.aspx").Item); –  Chloraphil Feb 7 '13 at 0:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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