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.
How do I create a folder called XMLFiles?
I assume once it's created I'd use this to get the assets root:
Then look for a content somehow named XMLFiles?
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";
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)
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
Great, I got this worked. I see folder is created.
Just a note: because you are running this in an initialization module, you should check for the folder for existence before creating it
Yeah, that totally make sense. Thanks for reminding.
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?
Not exactly, it is the context of scheduled job is always an empty SiteDefinition IIRC. That is why it fallback to the global asset root