1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Page saved and published, but still locked?

Page saved and published, but still locked?

4 posts, 0 answered
  1. Jenn Bohm
    Jenn Bohm avatar
    17 posts
    Registered:
    19 Aug 2009
    28 Mar 2010
    Link to this post
    I am creating pages programmatically, and after setting properties and permissions, adding content, etc, I call CmsManager.SavePage on the page, and then I call ICmsPage.Publish on the page. When I view the newly created page in the cms dashboard, it is listed as being "locked". What else do I need to do?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    28 Mar 2010
    Link to this post
    Hello Jenn Bohm,

    Could you try using the code shown  below

    var manager = new CmsManager();
    var newPage = manager.CreatePage("HELLO_WORLD");
    manager.SavePage(newPage);
    IPageTemplate template = manager.GetTemplate("Default");
    var editPage = (ICmsPage)manager.GetPage(newPage.ID, true);
    editPage.Staged.CheckOut();
    editPage.Staged.SetTemplate(template.ID, "Levels");
    editPage.Staged.CheckIn();

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Jenn Bohm
    Jenn Bohm avatar
    17 posts
    Registered:
    19 Aug 2009
    29 Mar 2010
    Link to this post
    Ok, I tried this, but I must be missing something, or doing something in the wrong order. I get the following exception at the call to CheckIn:

    "You cannot change a value of an object that is not in transaction."

    Here is my code:

    mgr_u = new UserManager();
    mgr_c = new CmsManager();
      
    // create the page under the selected category
    ICmsPage categoryPageGroup = GetPageByUrl("/" + wslrDomainName + "/" + ddlCategory.SelectedValue);
    ICmsPage newPage = mgr_c.CreatePage(Server.HtmlEncode(txtRetailerPageName.Text), categoryPageGroup.ID);
      
    // set the page properties
    newPage.Navigable = true;
    newPage.DenyAnonymous = true;
    newPage.Title = Server.HtmlEncode(txtPageTitle.Text);
    newPage.MenuName = Server.HtmlEncode(txtLinkText.Text);
      
    // give permissions to proper retailer
    string retailer = ddlRetailers.SelectedItem.Text;
    // first we want to deny all rights to everyone...
    string[] denyRoles = mgr_u.GetAllRoles();
    // then we want to grant view rights to the specific retailer and the wholesaler admins
    string[] grantRoles = { wslrID + "Retailer_" + retailer.Substring(7), wslrID + "Wholesalers" };
    ISecured secured = newPage as ISecured;
    secured.InheritsPermissions = false;
    secured.SetPermissions(0, CrudRights.View | CrudRights.Create | CrudRights.Modify | CrudRights.ChangePermissions | CrudRights.Delete, denyRoles);
    secured.SetPermissions(CrudRights.View, CrudRights.Create | CrudRights.Modify | CrudRights.ChangePermissions | CrudRights.Delete, grantRoles);
      
    // add the RetailerDocuments control to the page
    UserControl ctrl = new UserControl();
    Control myControl = ctrl.LoadControl("~/UserControls/RetailerDocuments/RetailerDocuments.ascx");
    newPage.Staged.AddControl("ContentPlaceHolder0", myControl);
                  
    // set the template
    IPageTemplate retailerPageTemplate = mgr_c.GetTemplate("RetailerPage");
    newPage.Staged.CheckOut();
    newPage.Staged.SetTemplate(retailerPageTemplate.ID, "ABW_Grey");
    newPage.Staged.CheckIn();
                  
    // save and publish the page
    mgr_c.SavePage(newPage);
    newPage.Publish();

    I've tried reordering the main chunks of code (setting the template, setting the permissions, setting the properties, adding the user control...), but I keep getting either the same exception, or a different one ("IOdbClass must be joined to a transaction.")

    Don't know what I'm missing here.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    29 Mar 2010
    Link to this post
    Hello Jenn Bohm,

    The error is thrown because the object (the page)  is not in Nolics transaction. You need to get the page using GetPage() of CmsManager class and then save or manipulate with this object.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Register for webinar
4 posts, 0 answered