Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
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);