Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get saved queries in tfs 2012 using c#

Tags:

c#

I need to get the queries in TFS 2012 in the "My Queries" folder. I found this article. But following that gives all the queries.

Folder Hierarchy

I want to get queries from the "My Queries" folder. This is what i have tried so far:

string selectedProject = this.listProjects.SelectedItem.ToString();
TfsTeamProjectCollection teamProjectCollection = TFSDetail.GetTeamProjectDetails(UrlPath);
if (teamProjectCollection != null)
{
     Project detailsOfTheSelectedProject = null;
     WorkItemStore workItemStore = 
           (WorkItemStore)teamProjectCollection.GetService(typeof(WorkItemStore));

     string folder = "My Queries";
     var project = workItemStore.Projects[selectedProject];
     QueryHierarchy queryHierarchy = project.QueryHierarchy;
     var queryFolder = queryHierarchy as QueryFolder;
     QueryItem queryItem = queryFolder[folder];
     queryFolder = queryItem as QueryFolder;               
}

When i add queryFolder to watch it gives following output:

Watch Window

How an I access the result and get those values?

like image 858
DevT Avatar asked Jul 24 '13 04:07

DevT


1 Answers

I solved this problem following way:

var project = workItemStore.Projects[selectedProject];
QueryHierarchy queryHierarchy = project.QueryHierarchy;
var queryFolder = queryHierarchy as QueryFolder;
QueryItem queryItem = queryFolder[folder];
queryFolder = queryItem as QueryFolder;
foreach (var item in queryFolder)
{
     listQueries.Items.Add(item.Name);
}
like image 196
DevT Avatar answered Sep 21 '22 10:09

DevT