November Happy Hour will be moved to Thursday December 5th.

Full proof way of knowing that a file uploaded is not under root node

Vote:
 

Hello,

For a business logic in an Episerver 9 CMS site. I have to find out that the media (pdf) uploaded by editor is not directly under the root node i.e. media, it must be under some folder. To acheive this I put in the following but I am uncertain that this will guarentee me the same output in all the environment, however it works in my local environment

var media = content as MediaData; // Getting the data from BlobFactory

var repository = ServiceLocator.Current.GetInstance(); // Get a repository instance

var folder = repository.Get(media.ParentLink); // Get the parent of the current document in context

if (folder.ParentLink.ID != 1) //Check for the Parent of parent

//Do the business logic if not true

is there another better way of doing this?

#173432
Dec 26, 2016 10:49
Vote:
 

Hi Amol.

It's indeed a way to achieve what you are looking for. Instead of hardcoding the ID of your parent, you could use either ContentReference.SiteBlockFolder, ContentReference.GlobalBlockFolder or the SiteAssetsRoot/GlobalAssetsRoot property of your current SiteDefinition (via ISiteDefinitionRepository)

Two tips to ensure you aren't forgetting some scenarios:

1. Ensure you restrict both the Site specific and the Global asset container. Suppose your authors should be prohibited from uploading PDF assets in the root of any of these.

2. Files can also be specific to a page or block - ensure this scenario is taken in to account as well.


Have a good day and happy holidays!


Casper Aagaard Rasmussen

#173435
Dec 26, 2016 16:50
Vote:
 

Thanks Casper :) 

Exactly what I was looking for. sometime stuffs are rather simple we make it complicated :D

#173444
Dec 27, 2016 13:14
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.