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);


            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.CheckIn("System account updated...");

1 Answer 1


It turns out that webpart object ID property cannot contain scandic characters and spaces.

I corrected that from my code and webpart is loading correctly.

xsltListViewWebPart.ID = "MyWpID";

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.