static void Main(string[] args) { SPSite site = null; SPWeb web = null; try { site = new SPSite("http://testSite/SubWeb/Pages/"); web = site.OpenWeb(); PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web); SPContentTypeId contentType = new SPContentTypeId("YourContentTypeId"); PageLayout[] layouts = publishingWeb.GetAvailablePageLayouts(contentType); PageLayout pageLayout = layouts[0]; string pageName = Guid.NewGuid().ToString() + ".aspx"; SPUser user = web.EnsureUser("DOMAIN\\USERNAME"); string createdDate = "2009-11-05T22:35:10Z"; string modifiedDate = "2009-11-05T22:35:10Z"; web.AllowUnsafeUpdates = true; PublishingPage newPage = publishingWeb.GetPublishingPages().Add(pageName, pageLayout); newPage.ListItem["Author"] = user.ID; newPage.ListItem["Editor"] = user.ID; newPage.ListItem["Created"] = createdDate; newPage.ListItem["Modified"] = modifiedDate; newPage.ListItem.UpdateOverwriteVersion(); web.AllowUnsafeUpdates = false; Console.WriteLine("OK"); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadLine(); } finally { web.Dispose(); site.RootWeb.Dispose(); site.Dispose(); } }
Remember Me
Page rendered at Thursday, March 11, 2010 3:35:58 AM (GMT Standard Time, UTC+00:00)
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.