Programmatically accessing block folder

Vote:
 

Hi all

How would I access a folder in the blocks file system area i,e, for a shared block.I am programmatically creating blocks but at the moment I can only put them in the root i.e.

ProductBlock productBlock = contentRepository.GetDefault<ProductBlock>(ContentReference.GlobalBlockFolder);

So i would like to get a reference to another folder for this call

Many Thanks for any all help

 

 

 

#76845
Nov 04, 2013 18:49
Vote:
 

If you go into admin mode and choose set access rights you can navigate to the global library and all your block folders. Point on a folder name you will see the id in the url.

#76846
Nov 04, 2013 19:14
Vote:
 

Thanks for your response Peter. But i don't want to bind to an id which might change as we go through environments. Can I pick it up programmatically by the folder name? A folder search type function - i'm struggling to find the part of the API that would allow me to do that.

 

Many Thanks

#76862
Nov 05, 2013 9:20
Vote:
 

You can read the folders like any other content. If you know that your folder is below the root folder and now the name you could do something like this.

IEnumerable<IContent> blockFolders = contentrepository.GetChildren<IContent>(ContentReference.GlobalBlockFolder);
ContentReference blockStartNode = null;

foreach (var f in blockFolders)
{
if (f.Name.ToLower().Contains(blockfoldername))
blockStartNode = f.ContentLink;
}

A bettor solution would maybe be to build a editordescripopr  and selectfactory class so you can make a nice dropdown on the starpage maybe where the system admin or editor can choose which block folder to use.

http://world.episerver.com/Blogs/Linus-Ekstrom/Dates/2012/9/EPiServer-7-Configuring-editors-for-your-properties/

 

#76865
Nov 05, 2013 10:42
Vote:
 

Brilliant. Thank you Peter - that's exactly it. I didn't realise that folders are just content. Thank you 

#76874
Nov 05, 2013 12:33
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.