Dynamically Create A mojoPortal Page

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
1/17/2012 4:47:30 PM
Gravatar
Total Posts 148

Dynamically Create A mojoPortal Page

Hi:

I'm creating a control that will have links to pages in mojoPortal. I want the pages to be created when users use my control instead of going through the "New Page" menu. Is there a function I can call that can add all the required info to the database?

1/18/2012 7:09:40 AM
Gravatar
Total Posts 18439

Re: Dynamically Create A mojoPortal Page

Hi,

The best way to learn how to do such things is to study the existing code that does it.

Web/AdminPageSettings.aspx.cs has relevant code.

Another useful example is probably the metaweblogapi.ashx.cs  which is designed for use with Windows Live Writer, it creates pages with a single html instance in the center pane, note that you also need to create the firendly url for pages as seen in these examples.

Keep in mind that you should not let untrusted users create pages and content as discussed at the bottom of our About page.

Hope that helps,

Joe

11/13/2012 12:10:35 PM
Gravatar
Total Posts 41

Re: Dynamically Create A mojoPortal Page

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();

11/13/2012 12:41:03 PM
Gravatar
Total Posts 18439

Re: Dynamically Create A mojoPortal Page

You did not copy the part that creates the friendly url correctly. Specifically you are only providing the realUrl not the friendly url on the friendly url object.

It should be more like this:

riendlyUrl newFriendlyUrl = new FriendlyUrl();
newFriendlyUrl.SiteId = siteSettings.SiteId;
newFriendlyUrl.SiteGuid = siteSettings.SiteGuid;
newFriendlyUrl.PageGuid =pageHall.PageGuid;
newFriendlyUrl.Url = "~/testhall";
newFriendlyUrl.RealUrl = "~/Default.aspx?pageid=" + pageId.ToInvariantString();
newFriendlyUrl.Save();

Instead of hard coding the url you could also use:

string urlString = SiteUtils.SuggestFriendlyUrl(pageHall.Name, siteSettings);

and then assign that as the url on both the page and the friendly url

Hope that helps,

Joe

11/13/2012 5:39:17 PM
Gravatar
Total Posts 41

Re: Dynamically Create A mojoPortal Page

Hi Joe,

Thanks!  Yes, of course that does help, as ever.  Mind you, I assumed that the constructor I used would set the url within the friendlyurl object, but obviously not!  It needed to be set to "testhall" of course, not "~/testhall", which is what I was passing into the constructor.  Anyway, passing it in subsequently does indeed work.

Yes, I realised you have the SuggestFriendlyUrl method there, but in this particular instance I need to 'hard code' the urls (albeit from another database) in order to maintain an existing set of urls that currently exist in the legacy system.

Thanks again for your speedy and helpful response - it really makes working with mojoPortal a relatively stress-free occupation knowing you and a few other experts are around to help when we get stuck!

Mike

You must sign in to post in the forums. This thread is closed to new posts.