0

I'm using follwoing code to map the Media files to Azure Blob. Code works fine. However, I want to map only the folders which does not contain the name "memberonly". Despite the condition check Kentico maps all the directories to Azure Blob. Giving the option to select which directories are mapped would be helpful.

Is there a way to acheive wha I'm after?

[assembly: RegisterModule(typeof(CustomInitializationModule))]
public partial class CMSModuleLoader
{
    public class CustomInitializationModule : Module //CMSLoaderAttribute
    {
        // Module class constructor, the system registers the module under the name "CustomInit"
        public CustomInitializationModule()
            : base("CustomInit")
        {
        }

        protected override void OnInit()
        {
            try
            {

                string[] subDirectories = Directory.GetDirectories(HttpContext.Current.Server.MapPath("~/ABC/media/"));

                if (subDirectories != null)
                {
                    for (int i = 0; i < subDirectories.Length; i++)
                    {
                        if (!subDirectories[i].ToLower().Contains("memberonly"))
                        {
                            // Creates a new StorageProvider instance
                            AbstractStorageProvider mediaProvider = new StorageProvider("Azure", "CMS.AzureStorage");

                            // Specifies the target container
                            mediaProvider.CustomRootPath = WebConfigurationManager.AppSettings["AzureContainer"];

                            // Makes the container publicly accessible
                            mediaProvider.PublicExternalFolderObject = true;

                            var directoryName = subDirectories[i].Substring(subDirectories[i].LastIndexOf(@"\") + 1);
                            // Maps a directory to the provider
                            //C:\Work\ItemGroup\APS\APS_Main_CJD\APS-Main\CMS\APS\media\APS-Image-Library
                            StorageHelper.MapStoragePath(string.Concat("~/APS/media/", directoryName), mediaProvider);
                        }
                    }
                }                                              

            }
            catch (System.Exception ex)
            {

            }

        }
    }
}
chamara
  • 12,649
  • 32
  • 134
  • 210

1 Answers1

2

As far as I know - NO. You are mapping the whole media library root directory and all its children. You can't exclude certain child folders.