Dev Notes

Notes on Development with Microsoft Technologies

VB.NET Translation for Thomas Conté’s Code

1 Comment

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)

Author: Chris Quick

I have been a developer of web based solutions since early 2001 delivering solutions to a wide array of organizations using ASP, ASP.NET and SharePoint. I was introduced to SharePoint in 2003 when the consulting firm I worked for at the time introduced it into the workplace. I began working with MOSS 2007 as soon as Microsoft released the RTM version in November 2006. The platform was implemented at the organization I worked for in 2007 and went live in March of that year. I was tasked with the administration and ongoing development of the platform. I currently work as a SharePoint Architect with Artis Consulting, developing solutions for a wide variety of business problems. The goal of this blog is to share my discoveries developing solutions with SharePoint. I welcome your comments and feedback to any post -- and I welcome suggestions for future topics.

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: Logo

You are commenting using your 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 )

Google+ photo

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

Connecting to %s