Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Context menu for document library

  Asked By: Gonzalo    Date: Nov 02    Category: Sharepoint    Views: 3761

I want to add a context menu for a particular document library.
I have added code in ows.js file located in

"c:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\1033"

The code is as follows:

strAction = "STSNavigate('" + ctx.HttpRoot + "/_layouts/" +L_Testpath + "/LnTDesignWorkflow.aspx?list=" + ctx.listName + "&item=" + currentItemID + GetRootFolder(ctx) + "')";
strImagePath = ctx.imagesPath + "AuditInfo.gif";
CAMOpt(m, strDisplayText,strAction,strImagePath);

My menuitem "AuditInfo" is added in the context menu but it appears in all the document library.
I want my item to be displayed for particular document library to which i have attached my dll..

How it can be achived.?



3 Answers Found

Answer #1    Answered By: Kareem Flynn     Answered On: Nov 02

So, Enclose this code  in if loop and in if clause specific document  libararies (ctx.listName == 'DocLib1' or ctx.listName == 'DocLib3')

Answer #2    Answered By: Tyron Calderon     Answered On: Nov 02

Making changes directly to ows.js is not supported by Microsoft. To
alter all document  libraries, I would modify my custom JavaScript file
identified in the ONET.XML Project element's CustomJSUrl attribute in
the Site Definition. This is an optional attribute that is not initially
implemented and it specifies a custom JavaScript file  that I place into
my Custom directory in the 60 hive (..\60\TEMPLATE\LAYOUTS\1033\Custom).
This custom JavaScript file contains script to execute within a site
created from the site definition and must be in place before the site is
templatized on the Template Picker Page.

The ONET Project element in all of my Site Definitions looks like this:
<Project xmlns:ows="Microsoft SharePoint"



Title="Todd Web Site"

If you only want to alter one or even just a few document libraries, I
would suggest adding a Content Editor Web Part to the Web Part List View
page (see my blog post about adding Web Parts in the browser even when
there isn't a Modify Shared Page link in the top right hand corner:
mindsharpblogs.com/.../285.aspx). Then place
JavaScript that overrides the built-in functionality into the Source

For instance, you could drop in this code:

<script language="JavaScript">
function Custom_AddDocLibMenuItems(m, ctx)
var L_AuditInfo = "Display Audit Info";

var strDisplayText = L_AuditInfo;
var strAction = "STSNavigate('" + ctx.HttpRoot +
"/_layouts/1033/Custom/LnTDesignWorkflow.aspx?list=" + ctx.listName +
"&item=" + currentItemID + GetRootFolder(ctx) + "')";
strImagePath = ctx.imagesPath + "checkin.gif";

//Add your new menu  item
CAMOpt(m, strDisplayText, strAction, strImagePath);

//Add a separator to the menu

//Returning false will render the standard menu items
return false;

I think that will do what you are trying to accomplish. I had to define
some text for L_AuditInfo. I also took out L_Testpath and replaced it
with my default Custom subdirectory.

You can check out the SDK details about altering the context  menu here:

Also, see my blog post about the AlternateCSS attribute for common
details about implementing this solution:

Didn't find what you were looking for? Find more on Context menu for document library Or get search suggestion and latest updates.