SharePoint custom context menu in custom list appears on folders and not just files
-
09-09-2019 - |
Question
I have 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 have 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}&ListItemID={ItemId}&Action=Copy"/>
This context menu appears on both files and folders, is it possible for my context memu to appear on files only?
Solution 2
I never figured out how to do this in code or XML but I got it working in JavaScript.
I added the following code to the 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.
OTHER TIPS
You can register the action on the content type instead. But that might not be suitable in your situation?
<CustomAction
Id="ContextMenu"
Location="EditControlBlock"
Title=Permissions"
**RegistrationType="ContentType"**
ShowInLists="FALSE"
ImageUrl ="~Site/_layouts/nks.PNG"
**RegistrationId="0x0101"**>
<UrlAction Url="your URL"/>
</CustomAction>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow