The SharePoint context menu in a custom list is displayed in folders, not just files

I created a custom list, here is the list template:

<ListTemplate Name="CustomDocumentLibrary"
            DisplayName="Document Library"
            Description=""
            BaseType="1"
            Type="10101"
            OnQuickLaunch="TRUE"
            SecurityBits="11"
            Sequence="110"
            Image="/_layouts/images/itdl.gif"
            DocumentTemplate="101" />

I added a custom action:

   <CustomAction
Id="1611D96C-ABBD-4021-9183-60D8440BEB95"
Location="EditControlBlock"
Title="Send to Document Management"
ImageUrl="/_layouts/images/cmCopy.gif"
RegistrationType="List"
RegistrationId="10101">
<UrlAction Url="~site/Lists/DocumentLibrary/Forms/SendToDM.aspx?ListId={ListId}&amp;ListItemID={ItemId}&amp;Action=Copy"/>

This context menu is displayed in both files and folders, is it possible that my context memu is displayed only in files?

+3
source share
3 answers

I never figured out how to do this in code or XML, but I got it in JavaScript.
I added the following code to AllItems.aspx:

<script type="text/javascript">
    function Custom_AddDocLibMenuItems(m, ctx) {
        var otype = currentItemFSObjType = GetAttributeFromItemTable(itemTable, "OType", "FSObjType");
        if (otype != 1) { // 1=folder
            var itemId = GetAttributeFromItemTable(itemTable, "ItemId", "Id");
            var listId = ctx.listName;
            var action = 'Go_To_Page("' + ctx.HttpRoot + '/_layouts/MyPage.aspx?ListId=' + listId + '&ListItemID=' + itemId + '");';
            var option = CAMOpt(m, 'Do Something', action, '/_layouts/IMAGES/10.gif', '', 1110);
            option.id = "ID_Do_Something";
        }
        return false;
    }

    function Go_To_Page(page) {
        window.location = page;
    }
</script>

One unfortunate side effect is the item is always first in the context menu.

+3
source

. ?

+4
<CustomAction
Id="ContextMenu"
Location="EditControlBlock"
Title=Permissions"
**RegistrationType="ContentType"**
ShowInLists="FALSE"
ImageUrl ="~Site/_layouts/nks.PNG"
**RegistrationId="0x0101"**>
    <UrlAction Url="your URL"/>
</CustomAction>
+2
source

Source: https://habr.com/ru/post/1706357/


All Articles