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

Forums / Developing with Sitefinity / How to prevent duplicates when creating content items using the DynamicModuleManager's CreateDataItem() method

How to prevent duplicates when creating content items using the DynamicModuleManager's CreateDataItem() method

3 posts, 1 answered
  1. Jeff
    Jeff avatar
    118 posts
    Registered:
    08 Jul 2011
    03 Jul 2013
    Link to this post
    I created a module using the Module builder. Now I'm trying to programmatically add content items but I want to prevent duplicates, kind of the same way that you cannot add 2 content items with the same url if you add content from the content menu. Is there a best practice to accomplish this or do I need to loop through the collection and check manually?

    When I programmatically add duplicate content items, set the same UrlName, call SaveChanges(), call Publsih() from ILifecycleDataItem and call SetWorkflowStatus() it doesn't throw any errors and then I end up with duplicates.

    Jeff
  2. Atanas Valchev
    Atanas Valchev avatar
    414 posts
    Registered:
    04 Jan 2016
    08 Jul 2013
    Link to this post
    Hello Jeff,

    Thank you for contacting us. 

    You are correct, you need to make sure that an item with the same url does not already exist. Depending on the number of items you have you could either manually look through the collection or query directly for an item with this url and depending on the results create the new item with a different url.

    Regards,
    Atanas Valchev
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  3. Jeff
    Jeff avatar
    118 posts
    Registered:
    08 Jul 2011
    08 Jul 2013 in reply to Atanas Valchev
    Link to this post
    Thank you.
3 posts, 1 answered