Power BI

Content by Charles Sterling

Notepad for Workitems: how to programmatically create workitems in Visual Basic for Team Foundation Server 2010

I was sitting in Richard’s Scrum course last week when he mentioned “I wish we had notepad for creating work items”.   Since I had that hour kind of free I decided to write it for him.

While I wanted the finished product to be a Windows gadget I decided to initially shim the UI in WPF…See Below.


The next step was to implement the the “Save” Button.


Imports Microsoft.TeamFoundation.Client
Imports Microsoft.TeamFoundation.WorkItemTracking.Client

Public Class TFSnotePad
    Public Function addWI(ByVal title As String, ByVal desc As String) As String
        Dim tfsServer As String = "http://localhost:8080/tfs"
        Dim teamFoundationServer1 As Microsoft.TeamFoundation.Client.TfsTeamProjectCollection = Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory.GetTeamProjectCollection(New Uri(tfsServer))
        Dim workItemStore1 As New WorkItemStore(teamFoundationServer1)
        Dim WorkItemStore As WorkItemStore = New WorkItemStore(tfsServer)
        Dim tfsProject As Project = WorkItemStore.Projects(0)
        Dim wIType As WorkItemType = tfsProject.WorkItemTypes("Bug")
        Dim workItem As WorkItem = New WorkItem(wIType)
        workItem.Title = Now.ToLongTimeString + title
        workItem.Description = desc
        Dim result As ArrayList = workItem.Validate()

        If result.Count > 0 Then
            Return (result(0).ToString + "There was an error adding this work item to the work item repository")
        End If

        For Each pr In WorkItemStore.Projects
            Return ("Added work items to: " + pr.Name.ToString)

    End Function
End Class

…I only needed to add references to the following three assemblies


And presto I was done!

…Now to get it working as a COM object from Javascript in a gadget (a Future post<g>)

Thanks for the great class Richard!