November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
The main operations for shared block instances are done through IContentRepository interface. To get a new instance of a shared block you call method GetDefault<T> where T is your block type. Note here that the instance you get back from GetDefault<T> will implement IContent even if your block type doesn't. What happens runtime is that when a shared block instance is created EPiServer will create a new type inheriting your block type, this new subclass will implement IContent.
Then after assigning values to your instance (note that you need to cast it to IContent to be able to set e.g. Name) you can persist the shared block instance by calling IContentRepository.Save (here you also need to cast it to IContent).
And you can then load the persisted instance by calling Get<T> with the reference you got back from Save.
Hi,
In my current project we are importing a bunch of data, where some of it will be built into shared blocks. I found this blogpost ( http://joelabrahamsson.com/entry/working-programmatically-with-local-blocks-in-episerver-7 ) from Joel but this deals with Local blocks.
Should we implement IContent for the Shared Block to be able to store it using IContentRepository.Save?