Virtual Happy Hour is canceled this month (March) due to Good Friday.
Try our conversational search powered by Generative AI!
AI OnAI Off
Virtual Happy Hour is canceled this month (March) due to Good Friday.
Hi,
Intead of asigning Category property -> contentCat.Category = new CategoryList(categoryIds.AsEnumerable());
try to use Add method to add categories:
var contentCat = sharedBlock as ICategorizable; // remove this line: // contentCat.Category = new CategoryList(categoryIds.AsEnumerable()); foreach(var id in categoryIds) { contentCat.Category.Add(id); }
I am creating blocks programmatically. But block contents getting created without category. How to set category to a block by code ?
Below is how my code look like
var sharedBlock = contentrepository.GetDefault(new ContentReference(FolderId));
sharedBlock.Name ="Name";
sharedBlock.Title ="Title";
var contentCat = sharedBlock as ICategorizable;
contentCat.Category = new CategoryList(categoryIds.AsEnumerable());
//Since this is a shared block instance I can cast it to IContent
var content = contentCat as IContent;
content.Name ="BlockName";
var savedReference = contentrepository.Save(content, EPiServer.DataAccess.SaveAction.Publish);