Scenario: I have external list and I want to show specific view on team sites homepage. I add XsltListViewWebPart with featurereceiver because I can init specific settings and view to it when creating new sites with my custom team site template.
Problem: When creating new site with custom template my code works ok (code below). When browsing to specific page where XsltListVewWebPart is added only title of the webpart is showed on the page.
When I take page to editmode and choose the wanted view by hand via webpart properties and apply changes and stop editing the page XsltListViewWebpart is showed correctly on my page. Correct view is also rendered and loading when page is in editmode... Thank you in advance!
I can tell more if needed.
var file = web.GetFile(web.ServerRelativeUrl + "/" + fullFileNameWithExtension);
file.CheckOut();
webPartManager = file.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
var view = list.Views[viewName];
XsltListViewWebPart xsltListViewWebPart = new XsltListViewWebPart();
xsltListViewWebPart.ID = webpartTitle;
xsltListViewWebPart.Title = webpartTitle;
xsltListViewWebPart.ChromeType = chromeType;
xsltListViewWebPart.WebId = list.ParentWeb.ID;
xsltListViewWebPart.ListName = list.ID.ToString("B").ToUpper();
xsltListViewWebPart.ListId = list.ID;
xsltListViewWebPart.ViewGuid = view.ID.ToString("B").ToUpper();
webPartManager.AddWebPart(xsltListViewWebPart, "Left", zoneIndex);
file.Update();
file.CheckIn("System account updated...");