Try our conversational search powered by Generative AI!

Deep Clone of ContentArea (Shared and For This Page/Block)


Hi guys,

I've been looking around for some code that will do a deep clone of a Content Area from one page/block to another. I already have something similar on the SetDefaultValues that works for only shared blocks but I wondered if anyone had any examples or code that can do a more deep clone.

E.g I have a setting in our main site settings that's a combination of shared blocks and page level blocks. I want a service/function that can deep clone from this configuration ContentArea on the settings to another, copying any shared references but also recreating all the blocks on that page/block level with all the values. 

I can see that in the docs there is a Copy method but I wondered if anyone had created something or used this without having to re-invent the wheel?



Feb 28, 2018 11:55

Hi pal,

I think Episerver language mananger has copy functionality (when you are creating new content in new langauge) - maybe there are some code cheats to look up?

Mar 23, 2018 8:40

Thanks Valdis, I've actually managed to accompish this. At the moment it's on a specific content type but I'm going to make it generic and post about it when I get the chance. I just ended

  1. Hooking in to the Events_CreatedContent for the types I want to clone
  2. using some reflection to work out the types that I want to clone
  3. Reloading the IContent from the IContentRepository
  4. Checking if the parent items's ContentTypeID == 3
  5. If it's 3 then it's a shared block so just add a content link
  6. If it's not 3 I used the IContentRepository.Copy method to clone the block in to the new item

Work pretty well apart from a weird exception about a properly not allowing nulls, but its a property that doesn't exisit anywhere lol. At the moment it's wrapped but I want to try and resolve it.

Mar 23, 2018 9:20
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.