As a side note, here is the translation of the code to VB.NET from Thomas Conté's post.
Dim PageFile As SPFile = _ManagedWeb.GetFile("default.aspx") Dim WebPartManager As WebPartPages.SPLimitedWebPartManager = PageFile.GetLimitedWebPartManager(Web.UI.WebControls.WebParts.PersonalizationScope.Shared) Dim TargetList As SPList = Me.GetList(ListName) Dim TargetListWebPart As WebPartPages.ListViewWebPart = New WebPartPages.ListViewWebPart() TargetListWebPart.ListName = TargetList.ID.ToString("B").ToUpper() TargetListWebPart.ViewGuid = TargetList.DefaultView.ID.ToString("B").ToUpper() TargetListWebPart.ChromeType = Web.UI.WebControls.WebParts.PartChromeType.TitleOnly WebPartManager.AddWebPart(TargetListWebPart, Zone, Ordinal) PageFile.Update()
1 comment:
I just realized this code was in the context of a class I have been developing for my organization, so here's the code without the reference to class members:
Dim Site as SPSite = New SPSite("http://server/sites/site")
Dim Web as SPWeb = SPSite.OpenWeb()
Dim PageFile As SPFile = Web.GetFile("default.aspx")
Dim WebPartManager As SPLimitedWebPartManager = PageFile.GetLimitedWebPartManager(PersonalizationScope.Shared)
Dim TargetList As SPList = Web.Lists(ListGUID)
Dim TargetListWebPart As New ListViewWebPart()
TargetListWebPart.ListName = TargetList.ID.ToString("B").ToUpper()
TargetListWebPart.ViewGuid = TargetList.DefaultView.ID.ToString("B").ToUpper()
WebPartManager.AddWebPart(TargetListWebPart, Zone, Ordinal)
PageFile.Update()
Post a Comment