Friday, February 20, 2009

How to display custom context menu in SharePoint list or Document library?

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

Whevever this menu is executes, it used JavaScript file which located in “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033\OWS.js.

OWS.js also allows users to implement custom menu options that can be used to create a custom menu in the context menu.

Or you can use a content editor web part can be used to implement the same if the context menu is required only in a particular site collection.

Add a content editor web part for the library or the list for which the context menu needs to be implement. Then 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 following custom menu for a Document Library

<script language="javascript">
function Custom_AddDocLibMenuItems(m, ctx)
var strDisplayText = "Navigate to Yahoo";
var strAction = "STSNavigate('’)";
var strImagePath = "";
// Add our new menu item
CAMOpt(m, strDisplayText, strAction, strImagePath);

// add a separator to the menu

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

Save the script and check the Hidden option in the Layout section of the tool pane, now see te context menu

We have seen that how we can add custom context menu for a Document Library, with Custom_AddDocLibMenuItems function, if you want to add custom context menu for a list then use Custom_AddListMenuItems function in place of Custom_AddDocLibMenuItems function.

Wednesday, February 11, 2009

Access Denied during MOSS Crawling

I seen varius people facing a common proble during MOSS crawling and they got following problem

Access is denied. Verify that either the Default Content Access Account has access to this repository, or add a crawl rule to crawl this repository. If the repository being crawled is a SharePoint repository, verify that the account you are using has "Full Read" permissions on the SharePoint Web Application being crawled. (The item was deleted because it was either not found or the crawler was denied access to it.)

To fix this with Microsoft KB article, follow the steps

1. Click Start, click Run, type regedit, and then click OK.
2. In Registry Editor, locate and then click the following registry key:
3. Right-click Lsa, point to New, and then click DWORD Value.
4. Type DisableLoopbackCheck, and then press ENTER.
5. Right-click DisableLoopbackCheck, and then click Modify.
6. In the Value data box, type 1, and then click OK.
7. Quit Registry Editor, and then restart your computer.

Thursday, February 5, 2009

How to Download all files from SharePoint Library?

Using following code we can download all the documents including Subfolders.

SPList list = web.Lists["Shared Documents"];
SPView view = list.Views["All Documents"];
SPQuery squery = new SPQuery(view);
squery.ViewAttributes = “Scope=\”Recursive\”";
SPListItemCollection items = list.GetItems(squery);

//Read all documents and write those files to Local Machine
foreach (SPListItem item in items)
byte[] binfile = item.File.OpenBinary();
FileStream fstream = new FileStream(”F:\\” + item.File.Name, FileMode.Create, FileAccess.ReadWrite);
fstream.Write(binfile, 0, binfile.Length);