In this example I will show how to use the WorkItemStore interface. This example will execute a stored query on the work items database and will extract the attachments from the work items returned from the query. This is a good training for working with the WorkItemStore interface.
private void ExtractWorkItemsAttachments(string teamFoundationServer, string teamProject, string storedQuery,
string saveTo)
{
//Logon to the server and create the needed objects
TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(teamFoundationServer);
tfs.EnsureAuthenticated();
WorkItemStore store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
Project tfsProject = store.Projects[teamProject];
StoredQueryCollection sqc = tfsProject.StoredQueries;
string querystring;
//Search for the query
foreach (StoredQuery query in sqc)
{
if (query.Name == storedQuery)
{
//Execute the query
querystring = query.QueryText;
querystring = querystring.Replace("@project", "'" + tfsProject.Name + "'");
WorkItemCollection workItems = store.Query(querystring);
//Extract the attachments
foreach (WorkItem workItem in workItems)
{
if (workItem.Attachments.Count > 0)
{
foreach (Attachment attachment in workItem.Attachments)
{
//Using WebClient to download the attachment
WebClient webClient = new WebClient();
webClient.Credentials = CredentialCache.DefaultCredentials;
string fileName = Path.Combine(saveTo, attachment.Name);
webClient.DownloadFile(attachment.Uri.AbsoluteUri, fileName);
}
}
}
}
}
}
2 comments:
It would be great to share a bit more on this matter. I’m glad I come across your site really informative post. Thanks for sharing this material.
www.n8fan.net
I discovered your weblog web site on google and verify a few of your early posts. Proceed to keep up the superb operate. I simply additional up your RSS feed to my MSN News Reader. In search of ahead to reading extra from you afterward!… free online casino slots
Post a Comment