Created content folder/assets folder doesn't appear in Asset Pane

Ben
Ben
Vote:
 

When an editor is uploading an image, a new folder is created in a specific directory (a sub-directory in another sub-directory of the root folder) and different sizes of the image are created and stored in the folder.

My problem is that I will not see the folder in the asset pane unless I reload the page. I am wondering what part of the code is messing up or if it is the location that I am trying to create the new folder.

            var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();

            //where new Models.Media.ImageFile().MediaFolder is the content reference of folder that the new folder should be created
            var contentAssetFolder = contentRepository.GetDefault<ContentAssetFolder>(new Models.Media.ImageFile().MediaFolder);

            contentAssetFolder.Name = content.Name.Substring(0, Path.GetExtension(content.Name).Length) + "_" + System.DateTime.Now.ToString("M-d-yy");
            
            return contentRepository.Save(contentAssetFolder, SaveAction.Publish, AccessLevel.NoAccess);
#206463
Edited, Aug 22, 2019 22:58
Vote:
 

If it appears after reload, it's probably correct code but that the tree structure in assets pane is cached until you do a full reload of page?

Not sure how to invalidate that cache though. 

#206531
Aug 23, 2019 10:53
Ben
Vote:
 

Hmm, I think I will refresh the cache after the folder is created just to see whether or not this is the problem.

#206554
Aug 23, 2019 16:50
Vote:
 

Hi Ben,

Yes, A full reload is required after adding and removing anything using code in the Episerver CMS.

Regards

Ravindra

#206571
Aug 24, 2019 10:06
Ben
Vote:
 

While I am still working on the cache refresh, hey Ravindra can you explain why the page needs to be refreshed! It would help me find a way around this situation.

#206608
Aug 26, 2019 17:07
Vote:
 

Hi Ben,

Episerver uses the Dojo JavaScript framework for the CMS UI and when you add or delete anything from code behind that basically adding the entries in the database and to view these new items in CMS you basically need to make a CMS data update call.

And I think refreshing the page will do the same for you.

#206614
Aug 27, 2019 8:12
Ben
Vote:
 

Hey Ravindra,

Yep, I came to the same conclusion about having to use Dojo. I was just unclear how the server-side communicated with the UI, if it is via the database then I should be halfway there on developing a solution. Thanks, Ravindra, if you have an example of a simple update then that would help as well!

#206645
Aug 27, 2019 16:02
Vote:
 

Great post. It was much needed. Love your simplistic style of explanation. :)

#206852
Sep 02, 2019 11:33
Ben
Vote:
 

Thanks, Jane

When I finally develop a solution I will post it here, but in the meantime know that the Dojo direction is most likely the right one. Just need to figure out how the backend and Dojo communicates' and if it is event-driven.

#206909
Sep 03, 2019 17:15