SaaS CMS has officially launched! Learn more now.

Creating an assets folder


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?

Feb 25, 2019 10:00

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";


Feb 25, 2019 11:35

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)



Feb 26, 2019 14:08

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

Feb 26, 2019 14:16


Great, I got this worked. I see folder is created.


Feb 26, 2019 14:20

Just a note: because you are running this in an initialization module, you should check for the folder for existence before creating it 

Feb 26, 2019 14:23

Yeah, that totally make sense. Thanks for reminding.

Feb 26, 2019 14:25

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.

Feb 26, 2019 15:47

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 

Feb 26, 2019 16:01

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?

Feb 27, 2019 16:52

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

Feb 27, 2019 17:20
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.