SharePoint: Change Page Layout through code

The following example changes the layout of a page to ArticleLeft.aspx.
using (SPSite site = new SPSite("http://aissp2013"))
{
    SPWeb rootWeb = site.RootWeb;
    PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(rootWeb);
    PageLayout[] layouts = pubWeb.GetAvailablePageLayouts();
    PageLayout layout = null;
    var matches = from l in layouts
                  where l.Name.Equals("ArticleLeft.aspx", StringComparison.OrdinalIgnoreCase)
                  select l;
    if (matches.Count<PageLayout>() > 0)
    {
        layout = matches.First<PageLayout>();
    }                     
    if (null != layout)
    {
        SPFile file = rootWeb.GetFile("/Pages/MyClients.aspx");
        if (PublishingPage.IsPublishingPage(file.Item))
        {
            PublishingPage page = PublishingPage.GetPublishingPage(file.Item);
            if (page.Layout != layout)
            {
                file.CheckOut();
                page.Layout = layout;
                page.Update();
                file.CheckIn("Changed layout");
                file.Publish("Initial Publish");                           
            }
        }
    }
}
profile for Nadeem Yousuf at SharePoint Stack Exchange, Q&A for SharePoint enthusiasts

+