Answers for "export TFS with attachments"

C#
0

export TFS with attachments

private static void ExportVso()
{
  // Connection to the Team Project Collection
  TfsTeamProjectCollection tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(
    new Uri("https://http://idahopower.visualstudio.com/defaultcollection"));
   
  // Get a WorkItemStore object for the Team Project Collection.
  WorkItemStore workItemStore = new WorkItemStore(tpc);
 
  // Run a query.
  WorkItemCollection queryResults = workItemStore.Query(
    @"SELECT *
    FROM WorkItems
    WHERE [Work Item Type] = 'Defect'
    AND Status IN ('New','Open','In-Progress', 'Pending Vendor', 'Re-open')
    AND [Responsible Group] IN ('AMS Delivery', 'AMS Ops')
    ORDER BY [Changed Date] DESC");
 
  // Get a WebClient object to do the attachment download
  WebClient webClient = new WebClient()
  {
    UseDefaultCredentials = true
  };
   
  // Loop through each work item.
  foreach (WorkItem workItem in queryResults)
  {
    // Loop through each attachment in the work item.
    foreach (Attachment attachment in workItem.Attachments)
    {
      // Construct a filename for the attachment
      string filename = string.Format("D:\\Defects\\{0}-{1}", workItem.Fields["HP QC ID"].Value, attachment.Name);
      // Download the attachment.
      webClient.DownloadFile(attachment.Uri,filename);
    }
  }
}
Posted by: Guest on June-25-2021

Code answers related to "export TFS with attachments"

C# Answers by Framework

Browse Popular Code Answers by Language