SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an issue with adding an XsltListViewWebPart to a page for a Document Library. When I do it using the code below everything works fine unless I create a folder and upload a document there. Such documents have a corrupted context menu.

When trying to open a menu I get the JavaScript error:

This item is no longer available. It may have been deleted by another user. Click 'OK' to refresh the page.

When I use ListViewWebPart instead of XsltListViewWebPart everything is OK (but this solution is not acceptable).

Code I'm using:

using (var site = new SPSite("http://moss_server/ct4"))
    using (SPWeb web = site.OpenWeb())
        SPFile page = web.RootFolder.Files["Default.aspx"];
        using (SPLimitedWebPartManager limitedWebPartManager =
            var webPart = new XsltListViewWebPart
                ListId = web.Lists["dl"].ID,
                ViewGuid = "{E58A6100-25F6-46EC-8C96-321EF710887B}"

            webPart.Title = "dl 14";
            limitedWebPartManager.AddWebPart(webPart, "", 100);

The list view web parts are fixed if I (after web part is added by code) go to 'Edit Web Part' from GUI and click 'OK' or 'Apply'.

What is missing in the above code? Is it some SharePoint bug?

share|improve this question
One question, why is the zone you're specifying in the AddWebPart method empty? – James Love Oct 11 '10 at 12:46
SharePoint copes with not specified zone. However specifying it (Left, Right or other proper zone) brings me to the same issue with context menu in folder documents. – Anonymous Oct 12 '10 at 7:30
Are you sure its the webpart configuration and not the XSLT supplied thats breaking the folder context menu? – Mauro Feb 28 '13 at 9:36

We had this problem when an upgrade was performed from 2007 to 2010. A DNS record that mapped the old server name to the new server IP was the issue - updating alternate access mappings fixed it.

share|improve this answer

Try to add:



limitedWebPartManager.AddWebPart(webPart, "", 100);

and see if it helps.

share|improve this answer

Can you try using a view that has no folders? If so does this work? If it works then I experienced the same problem in 2007, due to the way that sharepoint stores "folders" as a list item.

share|improve this answer
Documents placed in root folder are having proper context menu. Non-folder view cannot be used. – Anonymous Oct 12 '10 at 7:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.