This is correct as per the documentation located here:
You could also do this when calling save :
Sorry for such a general newbie question and thanks! Will play around with it.
Fujio, don't be apologising. We were all newbies once and by asking questions we only learn, in fact ask more questions I would say.
After taking a look at this explanations - https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/types/casting-and-type-conversions - if I get it correctly, another question appeared - is it safe to "transform" FormContainerBlock into IContent? Will FormContainerBlock after casting into IContent get back into form of FormContainerBlock (let's say after "Save")? Won't FormContainerBlock lack some (properties?, etc.) as IContent?
PS.: I also cast "ElementBlockBase" (of that "FormContainerBlock") to "ICotnent" inside that code the same way as casting "FormContainerBlock" to "IContent".
Everything you have said makes sense to me, so i had to have a look further.
Digging into the FormContainerBlock (in Episerver.Forms) it does not implement IContent.
So if I was trying to create a FormContainerBlock programmatically I would use this method:
var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>(); var contentTypeRepository = ServiceLocator.Current.GetInstance<IContentTypeRepository>(); var languageSelectorFactory = ServiceLocator.Current.GetInstance<LanguageSelectorFactory>(); var blockType = contentTypeRepository.Load<FormContainerBlock>(); var block = contentRepository.GetDefault<IContent>EPiServer.Forms.Configuration.Settings.Current.RootFolder, blockType.ID, languageSelectorFactory.Create(ContentLanguage.PreferredCulture.Name).Language); block.Name = "My new form conatiner block"; contentRepository.Save(block, SaveAction.Publish, AccessLevel.NoAccess);
Hope this helps.
the code below causes "Suspicious Cast" warning. Nevertheless everything works.
if(contentRepository.TryGet<FormContainerBlock>(copyContentEventArgs.ContentLink, out var formContainerBlock))
var writableFormContainerBlock = formContainerBlock.CreateWritableClone() as IContent;
The point is that without "as IContent" part, I could not call "Save" since it's requiring first parameter to be "IContent". And if I put "IContent" in "TryGet<>" instead of "FormContainerBlock", I then can't call "CreateWritableClone()" method.