Error Publishing Programmatically Created Page

Posted by Community Admin on 04-Aug-2018 20:37

Error Publishing Programmatically Created Page

All Replies

Posted by Community Admin on 03-Apr-2012 00:00

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: http://www.sitefinity.com/documentation/documentationarticles/developers-guide/sitefinity-essentials/pages/creating-pages 

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;
            break;
        
 
    //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;
 
        manager.SaveChanges();
 
        // Publish
        var bag = new Dictionary<string, string>();
        bag.Add("ContentType", typeof(PageNode).FullName);
        WorkflowManager.MessageWorkflow(pageNode.PageId, typeof(PageNode), null, "Publish", false, bag);
    

Posted by Community Admin on 04-Apr-2012 00:00

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.

This thread is closed