0

I have the following PowerShell script for creating custom action on a list in a document library.

Connect-PnPOnline -Url "https://[my_tenant].sharepoint.com/sites/[my_page]"
Add-PnPCustomAction -Name 'Test 1' -Title 'Test 1' -Description 'Test 1' -Group 'SiteActions' -RegistrationType 'List' -RegistrationId '101' -Location 'EditControlBlock' -Sequence 3010 -Url 'https://www.google.com'

This works fine and adds a custom action to every library on the SharePoint.

enter image description here

My question now is: How can I add the action only to a specific folder (folder 1) in a specific list (list 2)? The other items should not have this custom action!

- list 1
  - folder
    - file 1
    - file 2
- list 2
  - folder 1 <- only this one should have a custom action
    - file 1
    - file 2
  - folder 2
    - file 1

1 Answer 1

2

As per the Microsoft documentation, CustomAction Element:

Possible values RegistrationType includes:

  • None
  • List
  • ContentType
  • ProgId
  • FileType

So, you cannot directly provide folder name or URL/path and add custom action to only that one folder.

You can try below suggestions:

A. Using custom content type:

  1. Create a custom content type inheriting the default Folder content type
  2. Add custom content type to library
  3. Create a folder using the custom content type
  4. Add custom action to this particular content type by using RegistrationType = ContentType.

A. Using custom action to specific list (Not tested):

  1. As per the thread, you can show custom action in for only one list by using GUID/Name of list in RegistrationId.
  2. Then add some logic in EnabledScript function to check if the specific folder is selected or not.
  3. As per this documentation, you can get selected ItemId with menu item custom actions: Create custom actions to deploy with SharePoint Add-ins
1
  • 1
    thanks, the first suggestion works and is 'good enough' for us, so i didn't test the second one
    – bob
    Oct 6, 2022 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.