views:

21

answers:

3

Hi,

I want to open the workitem from outside visual studio using C# code. is it possible?

I tried with this

IWorkItemDocument widoc = null; try { string tfsName = "http://rd-tfs-no2:8080/tfs/siproducts"; var projectCollectionUri = new Uri(tfsName);

            var projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(projectCollectionUri, new UICredentialsProvider());
            projectCollection.EnsureAuthenticated();
            DocumentService docService = (DocumentService)Package.GetGlobalService(typeof(DocumentService));
            widoc = docService.GetWorkItem(projectCollection, id,this);
            docService.ShowWorkItem(widoc);
        }
        finally
        {
            widoc.Release(this);
        }

But help less Im getting null value for docService.

Any good suggestion?

A: 

You may want to try looking at the WorkItemStore object in the TFS API.

        TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(Constants.TEAMFOUNDSERVER);
        WorkItemStore workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
        string wiqlQuery = "SELECT [System.Id] FROM WorkItems";
        WorkItemCollection wic = workItemStore.Query(wiqlQuery);
        foreach (WorkItem wi in wic) 
        {
             //do work here
        }
bryanjonker
A: 

The Package only works when you are working on a Visual Studio plug-in. If you're looking for a way to display the work item, you could either do it by mapping fields to your winform/WPF application, or by shelling out to Internet Explorer and passing the work item ID into the URL for the web-based viewer.

Robaticus
A: 

To get the document service, try this:

var dte2 = Marshal.GetActiveObject("VisualStudio.DTE.10.0") as DTE2;
var witDocumentService = (DocumentService)dte2.DTE.GetObject("Microsoft.VisualStudio.TeamFoundation.WorkItemTracking.DocumentService");
joerage
Im getting error at secound line of your statement - Cannot convert type 'System.__ComObject' to 'Microsoft.VisualStudio.TeamFoundation.WorkItemTracking.DocumentService'.
Muralidharan TR