Search This Blog

Showing posts with label attachments. Show all posts
Showing posts with label attachments. Show all posts

Wednesday, June 06, 2007

Wednesday, May 30, 2007

Cropper TFS Work Item Plugin

It's been a while since I wrote here. Anyway, I hope this post will compensate for it. I read this week a post about SnagIt! integration with TFS. Since I use Cropper I've decided to write a plugin for TFS.
The plugin enables you to capture images directly to a new TFS work item attachments field. You can also add an attachment to an existing work item. You can download it from here. Read the read me file for installation guide and how to use it.
The plugin uses the WorkItemFormControl to edit the work item. I will explain in future posts on how to use it.
I'm planning to add the sources to Cropper Plugins project in CodePlex.
The plugin is in it's early stages. I would be happy to hear your comments.

Thursday, April 12, 2007

Extracting Images from Work Items Attachments

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);
}
}
}
}
}
}