VB.NET Translation for Thomas Conté’s Code

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)

One thought on “VB.NET Translation for Thomas Conté’s Code

  1. 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()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s