var contentRepository = ServiceLocator.Current.GetInstance();
var folder = contentRepository.GetBySegment(SiteDefinition.Current.RootPage, name, LanguageSelector.AutoDetect()) as ContentFolder;
if (folder == null)
folder = contentRepository.GetDefault(SiteDefinition.Current.RootPage);
folder.Name = name;
contentRepository.Save(folder, SaveAction.Publish, AccessLevel.NoAccess);
return folder as ContentFolder;
above code throws exception. I am not able to figure out what is causing the exception?
Any help would be appreciated.
The exception message actually tells you a fair bit here.
You are trying to create a system content folder under the System root page. This isn't allowed, as you are trying to create a media folder within the pages section of the content tree. I'm not sure exactly what you are trying to do, but I'll assume you are trying to create a new content folder to store blocks or images in. In which case you should create them either within the Global Assets folder (meaning items are available to all sites in a multi-site scenario) or the Site specific assets folder (for blocks and images limited to a single site)
In your code you need to replace SiteDefinition.Current.RootPage with either:
I have noticed that SysRoot does not allow any custom content folder class under itself. I was able to add ContentFolder and all of my custom folder under content folder.