Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

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
2  
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
add comment

3 Answers 3

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
add comment

Try to add:

limitedWebPartManager.SaveChanges(webPart);

after

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

and see if it helps.

share|improve this answer
add comment

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
add comment

Your Answer

 
discard

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