Hi,
I'm doing something similar. I have a situation where I need to create a page dynamically under very controlled circumstances. This is to enable a legacy system to be integrated into a mojo site.
I've borrowed code from the PageSettings.aspx page and when I run it I find that a new page record is created in mp_Pages and it looks fine. I realised after a while I also need to create a FriendlyUrl to link the page url to the real url, so I borrowed the code that appears to do this, but I don't get an entry in mp_FriendlyUrls. I can't work out where I'm going wrong. I've tried to keep things as simple as possible at the moment (so not much checking of existing entries going on) but here's my code below. hallPageID is the id of the parent page, btw, and is set earlier. Have I missed something?
Thanks in anticipation!
//just create a single page for now
pageHall = new PageSettings();
parentPage = new PageSettings(siteSettings.SiteId, hallPageID);
pageHall.ParentId = parentPage.PageId;
pageHall.ParentGuid = parentPage.PageGuid;
pageHall.PageName = "thisisatest";
pageHall.PageTitle = "This is a test";
pageHall.SiteId = siteSettings.SiteId;
pageHall.SiteGuid = siteSettings.SiteGuid;
pageHall.Url = "~/testhall";
pageHall.UseUrl = true;
pageHall.AuthorizedRoles = parentPage.AuthorizedRoles;
pageHall.EditRoles = parentPage.EditRoles;
pageHall.CreateChildPageRoles = parentPage.CreateChildPageRoles;
pageHall.AllowBrowserCache = false;
pageHall.MenuImage = "blank.gif";
pageHall.ChangeFrequency = parentPage.ChangeFrequency;
pageHall.PageOrder = PageSettings.GetNextPageOrder(siteSettings.SiteId,parentPage.PageId);
bool saved = pageHall.Save();
//now need to create a friendly url
String friendlyUrlString = pageHall.Url.Replace("~/", String.Empty);
FriendlyUrl friendlyUrl = new FriendlyUrl(siteSettings.SiteId, friendlyUrlString);
friendlyUrl.SiteGuid = siteSettings.SiteGuid;
friendlyUrl.PageGuid = pageHall.PageGuid;
friendlyUrl.RealUrl = "~/Default.aspx?pageid=" + pageHall.PageId.ToString(CultureInfo.InvariantCulture);
friendlyUrl.Save();