Monday, January 14, 2008

Create a custom context menu in SharePoint list or Document library

The context menu is the drop down menu displayed when a document library item or a list item is selected.



This menu is executed with the help of a JavaScript file located in "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033\OWS.js.


The OWS.js file is the java script file that implements the functionality for the context menu. OWS.js also lets users to implement custom menu options that can be used to create a custom menu in the context menu. Changes made to the OWS.js java script file is implemented or reflected across all the applications in the server farm.
Alternatively, a content editor web part can be used to implement the same if the context menu is required only in a particular site collection.

Steps:

1. Go to Edit Page for the page or site for which you want to display the context menu.


2. Add a content editor web part for the library or the list for which the context menu needs to be applied.



3. Click on the link that says open the tool and pane which opens up the tool pane. In the Source Editor Web part add the following JavaScript code to add custom menu for a Document Library within the script tag.

function Custom_AddDocLibMenuItems(m, ctx)
{
var strDisplayText = "Navigate to Google";
var strAction = "STSNavigate('http://www.google.com')";
var strImagePath = "";

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

// add a separator to the menu
CAMSep(m);

// false means that the standard menu items should also be rendered
return false;
}


4. Save the script and check the Hidden option in the Layout section of the tool pane.

5. The context menu will be visible now.



6. In order to add a custom context menu for a Document Library, implement the custom functionality using the Custom_AddDocLibMenuItems function and in order to add a custom context menu for a list, implement the custom functionality using the Custom_AddListMenuItems function.

"One or more field types are not installed properly. Go to the list settings page to delete these field" error from SPQuery

When using SPQuery often one might often encounter this error. This errror is caused because the field that you are refrencing in your CAML query is repersented differently internally. This can be because either you renamed a column or another site column with the same name exists.

Though the Display name of the column may be the say the internal column name can be different in SharePoint. SPQuery Fieldref requires the internal column name in order to perform the query. Remedies for this error are,

1. Use the U2UCamlQueryBuilder to re-construct the query and determine the actual internal field name or
2. Delete the field and recreate it.

Happy coding :-)

Monday, January 14, 2008

Create a custom context menu in SharePoint list or Document library

The context menu is the drop down menu displayed when a document library item or a list item is selected.



This menu is executed with the help of a JavaScript file located in "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033\OWS.js.


The OWS.js file is the java script file that implements the functionality for the context menu. OWS.js also lets users to implement custom menu options that can be used to create a custom menu in the context menu. Changes made to the OWS.js java script file is implemented or reflected across all the applications in the server farm.
Alternatively, a content editor web part can be used to implement the same if the context menu is required only in a particular site collection.

Steps:

1. Go to Edit Page for the page or site for which you want to display the context menu.


2. Add a content editor web part for the library or the list for which the context menu needs to be applied.



3. Click on the link that says open the tool and pane which opens up the tool pane. In the Source Editor Web part add the following JavaScript code to add custom menu for a Document Library within the script tag.

function Custom_AddDocLibMenuItems(m, ctx)
{
var strDisplayText = "Navigate to Google";
var strAction = "STSNavigate('http://www.google.com')";
var strImagePath = "";

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

// add a separator to the menu
CAMSep(m);

// false means that the standard menu items should also be rendered
return false;
}


4. Save the script and check the Hidden option in the Layout section of the tool pane.

5. The context menu will be visible now.



6. In order to add a custom context menu for a Document Library, implement the custom functionality using the Custom_AddDocLibMenuItems function and in order to add a custom context menu for a list, implement the custom functionality using the Custom_AddListMenuItems function.

"One or more field types are not installed properly. Go to the list settings page to delete these field" error from SPQuery

When using SPQuery often one might often encounter this error. This errror is caused because the field that you are refrencing in your CAML query is repersented differently internally. This can be because either you renamed a column or another site column with the same name exists.

Though the Display name of the column may be the say the internal column name can be different in SharePoint. SPQuery Fieldref requires the internal column name in order to perform the query. Remedies for this error are,

1. Use the U2UCamlQueryBuilder to re-construct the query and determine the actual internal field name or
2. Delete the field and recreate it.

Happy coding :-)