You should be able to create a content of type ContentFolder under the SiteAssetsRoot. Something like
var folder = _contentRepository.GetDefault<ContentFolder>(SiteDefinition.Current.SiteAssetsRoot);
folder.Name = "XMlFiles";
_contentRepository.Save(...);
Hi Quan Mai,
What should be the access level while saving that? Or, am I doing something wrong?
I tried to implement it in Alloy Site in Initialization Module. (Please see below screenshot)
Thanks,
Praful
You are requiring the user to run the code to have Administer access right. It might make senses to run this code with AccessLevel.NoAccess
Just a note: because you are running this in an initialization module, you should check for the folder for existence before creating it
Brilliant thank you. I knew it would be something obvious once someone helped out.
How would I go about putting the folder in the "For This Site" rather than "For All Sites". Doesn't seem to make a difference if I use SiteDefinition.Current.GlobalAssetsRoot or SiteDefinition.Current.SiteAssetsRoot.
I think the reason is that you only have one site configured. If you have multiple sites configured then For This site and For All sites will be distinct
When running via the scheduled job it always goes to the "For All Sites". I have noticed when then using the SiteAssetsRoot on the website code area it actually points "For This Site" and the GlobalAssetsRoot points to "For All Sites". Is this because under the Admin area it doesn't know which site you want?
I'm trying to create a data folder under the Media tab to store some xml files. I'm able to create my xml files on the root of the assets folder without any issues.
I've found example code that just says 2 lines, not really helpful.
https://world.episerver.com/documentation/developer-guides/CMS/Content/assets-and-media/Content-assets-and-folders/
How do I create a folder called XMLFiles?
I assume once it's created I'd use this to get the assets root:
_contentRepository.GetDefault<GenericMedia>(SiteDefinition.Current.SiteAssetsRoot);
Then look for a content somehow named XMLFiles?