How to prevent duplicates when creating content items using

Posted by Community Admin on 04-Aug-2018 19:07

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

All Replies

Posted by Community Admin on 03-Jul-2013 00:00

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

Posted by Community Admin on 08-Jul-2013 00:00

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

Posted by Community Admin on 08-Jul-2013 00:00

Thank you.

This thread is closed