1

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

1 Answer 1

0

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 that you have read and understand our privacy policy and code of conduct.

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