I have a Home.aspx page with three web parts on the top, and now I want to add a new one above them, but everytime is being created in the last position. I've tried modifying zoneIndex property for all of them from 1 to 3, and after that adding the new one with zoneIndex set to 0, but it stills being at the end of the layout. So this is what I want, but I'm having this (sorry for the poor images).
Code to move one position the existing web parts:
Dim webPartManager As SPLimitedWebPartManager = sitioWeb.GetLimitedWebPartManager(sitioWeb.ServerRelativeUrl & "/SitePages/Home.aspx", PersonalizationScope.Shared) Dim webPartList As IEnumerable = From webPart In webPartManager.WebParts Select webPart Dim zoneIndex As Integer = 1 Dim wpCount As Integer = webPartManager.WebParts.Count For Each eachWebPart In webPartList Stop eachWebPart.Hidden = False eachWebPart.ZoneID = "wpz" eachWebPart.PartOrder = zoneIndex webPartManager.MoveWebPart(eachWebPart, eachWebPart.ZoneID, zoneIndex) zoneIndex = zoneIndex + 1 webPartManager.SaveChanges(eachWebPart) Next
Code to add the new web part:
Dim webPartManager As SPLimitedWebPartManager = sitioWeb.GetLimitedWebPartManager(sitioWeb.ServerRelativeUrl & "/SitePages/Home.aspx", PersonalizationScope.Shared) Dim newWebPart As ContentEditorWebPart = New ContentEditorWebPart() newWebPart.Title = "WP_Header" newWebPart.ZoneID = "wpz" newWebPart.PartOrder = 0 newWebPart.ContentLink = Site.ServerRelativeUrl & "/SiteAssets/DocumOblig.txt" newWebPart.ChromeState = PartChromeState.Normal newWebPart.ChromeType = PartChromeType.None webPartManager.AddWebPart(newWebPart, "wpz", 0) webPartManager.SaveChanges(newWebPart)
There is also two things that are confusing me:
- On the new web part, if I set ZoneID as "wpz" it doesn't shows it, but if I name it with "Bottom" or "Top", it appears in the page.
- Always, when I go to the Edit mode on Home.aspx page, it just shows me the web parts which are already created, but not this new one.
Anyone knows why this could be happening?