Question

As you may know, when you create a Community site, it automatically creates a discussion list which is added to /SitePages/Community Home.aspx which looks like so.

enter image description here

I am trying to replace this with another list that I have created programmatically and have it look just like the image above.

This is what I have attempted:

//Get the community homepage.
SPFile communityHomepage = web.GetFile("/SitePages/Community Home.aspx");
SPLimitedWebPartManager webPartManager = communityHomepage.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);

//Index 0 contains the default discussion board list for a community site template.
webPartManager.WebParts[0].AllowClose = true;

//Close the default list web part.
webPartManager.CloseWebPart(webPartManager.WebParts[0]);
webPartManager.SaveChanges(webPartManager.WebParts[0]); 
//Get my list that I want to replace it with.
SPList discList = web.Lists[discBoardName];

XsltListViewWebPart listViewWebPart = new XsltListViewWebPart();
listViewWebPart.ListId = discList.ID; 
listViewWebPart.ListName = discList.ID.ToString("B").ToUpper();
listViewWebPart.Title = discBoardName;
listViewWebPart.ClientRender = true;
listViewWebPart.Toolbar = "Standard";
SPView view = discList.Views["Subject"];
listViewWebPart.ViewId = int.Parse(view.BaseViewID);
listViewWebPart.XmlDefinition = view.GetViewXml();
webPartManager.AddWebPart(listViewWebPart, "Main", 0);
webPartManager.SaveChanges(listViewWebPart);
discList.Update();
listViewWebPart.Dispose();
webPartManager.Dispose();

The default list webpart view is closed fine, but the one I am trying to add is added outside of the page layout all the way at the bottom and does not look like I want it to.

enter image description here

I have also tried using

string zoneId = webPartManager.GetZoneID(webPartManager.WebParts[0]);

and passing zoneId to AddWebPart(), but that didn't work either. So how do I add this List to the page in the correct location with the correct aesthetic look?

Était-ce utile?
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top