Limit file types to media library per directory

Tim Valdez asked on October 17, 2023 21:19

Custom Kentico 11 site. Is there an easy way to limit what people can upload to the ML based on what directory (folder) they are trying to upload to? Our ML is set in a hierarchy of IMages or Documents. Then under those are sub-folders based on what section of the company the content is about. We are having people upload documents in their section of the Images area and vice-versa and it's a mess.

Since I don't have the CMS source code I tried to directly edit the file upload page and add text next to the [Upload] button at the top as a reminder, but that was a mess since DirectFileUploader.ascx is used on every upload in the file list below the main Upload button.

So even if I knew what code file to edit to add a test that first looks at the top directory selected in the folder list on the left frame, and then based on that I could add a reminder message to just the top [Button] frame, that would be great! Or even if i could list the parent directories and what the allowed file extensions are for each one.

Yes, I know about Settings/Content/Media/Security but that is a global list of allowed file extensions and is not able to be customized per folder.

Recent Answers


Juraj Ondrus answered on October 18, 2023 06:05

I would use global event handler and catch the media file object type - insert before event. Check the folder, check the uplaoded file and then either continue and let the file to be saved and uploaded or cancel the operation.
Or, another option would be creating a fully custom module with custom logic, where you will do the check before you call the media file API. So the users will have access to this custom module only.

0 votesVote for this answer Mark as a Correct answer

Tim Valdez answered on October 18, 2023 16:37

Well, not sure how to even begin doing that since, like I said, I can only edit the existing Kentico CMS files manually because I don't have a project/solution file for the CMS code itself.

Is there a specific file (e.g. MediaFileUpload.ascx.cs) that I can modify to achieve this?

Or failing that, even easier would be to add text to the file upload frame at the top near the [Upload] button to remind users not to upload doc files into the image directories and vice versa.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on October 19, 2023 06:31

Well, for global event handler you need to at least build the solution, e.g. using MS Build tools.
You can see what page is displaying given part of UI e.g. like described here. But it is possible that the UI page is driven by UI element and DB content. And if you are using web appliction project type, you need to build the change too.
But since oyu said you do not have all the solution files, it looks like the project is precompiled so the changes made to the code files will most likely not apply. You need to get the original, full solution with all the files to do the changes.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.