ContentLink empty after creating a page

Member since: 2010


This is the scenario I have:

- I am creating and publishing a page through code, in brief:

var newPage = _contentRepository.GetDefault<PageData>(destination.ContentLink, someid);
newPage.PageName = "some pagename";
_contentRepository.Save(newPage, SaveAction.Publish, AccessLevel.NoAccess);

- I am subscribed to PublishingContent event, but the e.ContentLink and e.Content.ContentLink of the newly created page is an empty reference (ID is null).

When I save the page first, then publish it, these are not empty any longer:

            _contentRepository.Save(newPage, SaveAction.Save, AccessLevel.NoAccess);
            _contentRepository.Save(newPage, SaveAction.Publish, AccessLevel.NoAccess);

What flag do I need to use to avoid having two save actions, anyone knows?



#131426 Jul 24, 2015 10:18


    Maybe the PublishingContent is too early event for new pages and you could use PublishedContent event instead.

    It looks like the PublishingContent event is raised before content save. And I think that after you saved the page in PublishingContent event you have access to previously saved page.

    #131427 Jul 24, 2015 10:47
  • Member since: 2010


    Thx for the answer, but in this case, I would need to publish the page again to save a value, so it's the same extra save.

    I thought I could use a combination of actions in the event to have this value saved.

    I might consider subscribing to Saving event instead. // update - that didn't help either, for now I have two actions Save, then Publish. If anyone knows a better solution, let me know.



    #131428 Edited, Jul 24, 2015 10:50
  • Member since: 2008

    As you already know, the main differences of the -ING and -ED are

    SavING and publishING means that it's about to get stored in the database (unless already stored previously) and don't have an ID yet.

    SavED and publishED means that it has been saved and has received an ID.

    So the main question is, what do you want to do with your content and the ID?

    #131451 Jul 27, 2015 13:15
  • Member since: 2010

    My trouble is not -ING vs -ED, it's the fact that Publishing gets called before Saved.

    If I do stuff in published, that's the same as saving twice. Maybe that's fine, but I wanted to know if there is a better way.

    #131452 Jul 27, 2015 13:24