I want to programmatically create a Webpart page (.aspx file) for Sharepoint 2010. I already found this code snippet:
public static PublishingPage CreatePage(string fileName, string title)
{
PublishingWeb pWeb = PublishingWeb.GetPublishingWeb(Web);
PageLayout[] layouts = pWeb.GetAvailablePageLayouts();
PageLayout layout = layouts[0];
foreach (PageLayout p in layouts)
{
if (p.Name.Equals("BlankWebPartPage.aspx"))
{
layout = p;
break;
}
}
try
{
PublishingPage newPage = pWeb.GetPublishingPages().Add(fileName, layout);
newPage.Title = title;
newPage.Update();
return newPage;
}
catch (Exception)
{
return null;
}
}
But my problem is SharePoint Foundation Server does not have the Publishing part but I have to run it on a SharePoint Foundation Server. Is it possible to create a Webpart Page without PublishingWeb?
greets