8

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 =
            page.GetLimitedWebPartManager(PersonalizationScope.Shared))
        {
            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?

3
  • One question, why is the zone you're specifying in the AddWebPart method empty?
    – James Love
    Oct 11, 2010 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, 2010 at 7:30
  • 2
    Are you sure its the webpart configuration and not the XSLT supplied thats breaking the folder context menu?
    – Mauro
    Feb 28, 2013 at 9:36

3 Answers 3

1

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.

1

Try to add:

limitedWebPartManager.SaveChanges(webPart);

after

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

and see if it helps.

0

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.

1
  • Documents placed in root folder are having proper context menu. Non-folder view cannot be used.
    – Anonymous
    Oct 12, 2010 at 7:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.