Click here to Skip to main content
15,071,581 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having the following error in following code while trying to get workitem store
. I searched everywhere but i couldn't find any solution please help :(

CSS
TF31002: Unable to connect to this Team Foundation Server: http://hostname:8080/tfs/tpCollectionName/tpname
Team Foundation Server Url: http://hostname:8080/tfs/tpCollectionName/tpname.



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.TeamFoundation;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Common;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace ModifyWorkItems
{
public static class CWorkItems
{
public static void RemoveAllWorkItems()
{
List<workitem> workItems = new List<workitem>();
try
{
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName("http://hostname:8080/tfs/tpCollectionName/tpname/"));

// WorkItemStore store = tfs.GetService<workitemstore>();
// TeamFoundationServer tfs = new TeamFoundationServer("http://hostname:8080/tfs/tpCollectionName/tpname/");

// WorkItemStore m_store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
WorkItemStore store = new WorkItemStore(tfs);


string wiql = "SELECT ID FROM WorkItems WHERE ([Work Item Type]='Task' OR [Work Item Type]='User Story' OR [Work Item Type]='Bug') AND [State] <>'Closed' AND [AreaPath] <> '/Entegrasyon' ";
WorkItemCollection wicr = store.Query(wiql);

foreach (WorkItem wi in wicr)
{
wi.Open();
wi.Fields["State"].Value = "Removed";
wi.Save();
wi.Close();
}

}
catch (Exception ex)
{
Console.WriteLine(ex.Message);

}


}
}
}
Posted

Try this:

C#
TfsTeamProjectCollection tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(yourTFSUri);
WorkItemStore workitemstore = tpc.GetService<WorkItemStore >();
   
v2
Comments
Ayshine 5-Jun-14 3:54am
   
and this line of code also works so I'm accepting Solution
I changed

TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName("http://hostname:8080/tfs/tpCollectionName/tpname/"));

line into
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName("http://hostname:8080/tfs/tpCollectionName/"));

this line and my problem was solved

I had to use TPC Uri instead of TP Uri
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900