More in this section

Forums / Bugs & Issues / Error Publishing Programmatically Created Page

Error Publishing Programmatically Created Page

2 posts, 0 answered
  1. Rory
    Rory avatar
    44 posts
    22 Mar 2012
    03 Apr 2012
    Link to this post
    Hello.  I am trying to get basic page creation figured out but am running into a problem right off the bat.  i created a simple control + designer which will take in a Name and Guid and then use that info to create a duplicate page at the root node level.  i pretty much copied the example code provide at: 

    i have a button on the page that fires the code to do my page duplication.

    it works until it gets to : " WorkflowManager.MessageWorkflow(pageNode.PageId, typeof(PageNode), null, "Publish", false, bag); "

    at which point i get an exception stating: "You are trying to access item that no longer exists. The most probable reason is that it has been deleted by another user."

    the page is getting created and put into the root node in a draft status so i dont thinks its talking about that.  i did setup a basic workflow for the site.  i am logged in as administrator. using SiteFinity 5.

    any ideas why i get this error when trying to publish?  any help is appreciated.

    code below:
    private void buildPages()
        PageManager manager = PageManager.GetManager();
        var pageDataId = Guid.NewGuid();
        Guid parentPageNodeId = SiteInitializer.FrontendRootNodeId;
        PageNode parent = manager.GetPageNode(parentPageNodeId);
        PageData pageData = null;
        PageNode pageNode = null;
        //check if partner page already exists already exist
        bool alreadyExists = false;
        foreach (PageNode pn in parent.Nodes)
            if (pn.Title == PartnerName)
                alreadyExists = true;
        //if none found then create
        if (!alreadyExists)
            pageData = manager.CreatePageData(pageDataId);
            pageData.HtmlTitle = PartnerName;
            pageData.Title = PartnerName;
            pageData.Description = PartnerName;
            pageData.Culture = Thread.CurrentThread.CurrentCulture.ToString();
            pageData.UiCulture = Thread.CurrentThread.CurrentUICulture.ToString();
            pageNode = manager.CreatePage(parent, Guid.NewGuid(), NodeType.Standard);
            pageNode.Page = pageData;
            pageNode.Name = PartnerName;
            pageNode.Description = PartnerName;
            pageNode.Title = PartnerName;
            pageNode.UrlName = Regex.Replace(PartnerName.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
            pageNode.ShowInNavigation = true;
            pageNode.DateCreated = DateTime.UtcNow;
            pageNode.LastModified = DateTime.UtcNow;
            // Publish
            var bag = new Dictionary<string, string>();
            bag.Add("ContentType", typeof(PageNode).FullName);
            WorkflowManager.MessageWorkflow(pageNode.PageId, typeof(PageNode), null, "Publish", false, bag);
  2. Rory
    Rory avatar
    44 posts
    22 Mar 2012
    04 Apr 2012
    Link to this post
    well i fixed it and surprise surprise, it was my own fault.

    i was using pageNode.PageId instead of pageNode.Id. duh.

    fun fact: Page Groups do not need to be published.  Only Pages.
2 posts, 0 answered