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?