- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试使用从 Nuget 下载的 TeamFoundation/VisualStudio C# API,以编程方式从 VSTS 中的用户故事下载 90 多个附件。我试图使用这个例子:https://intellitect.com/downloading-attachments-from-tfs/
但是,该代码似乎已过时。我似乎找不到文章中提到的这些确切的包:nuget-bot.Microsoft.TeamFoundation.Clientnuget-bot.Microsoft.TeamFoundation.WorkItemTracking.Client
但是,我下载了那里的 TFS 包,例如 Microsoft.TeamFoundationServer.Client 和 Microsoft.TeamFoundationServer.ExtendedClient,但 WorkItem 类似乎不再有附件。有人知道我在哪里可以找到 Attachments 属性吗?我在 Visual Studio 中浏览了对象浏览器,但找不到它。或者您可以建议一个替代解决方案来从工作项中获取附件吗?谢谢。
最佳答案
WebClient cannot authenticate to VSTS correctly. Instead of using WebClient to download the file, you can use
WorkItemServer.DownloadFile()
method inMicrosoft.TeamFoundation.WorkItemTracking.Proxy
to download the file. See this thread for details.
您可以使用以下示例下载特定工作项的附件:
注意:安装nuget包Microsoft.TeamFoundationServer.ExtendedClient
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Proxy;
using System;
using System.IO;
namespace VSTS_DownloadWITAttachment
{
class Program
{
static void Main(string[] args)
{
TfsTeamProjectCollection ttpc = new TfsTeamProjectCollection(new Uri("https://account.visualstudio.com/"));
ttpc.EnsureAuthenticated();
WorkItemStore wistore = ttpc.GetService<WorkItemStore>();
WorkItem wi = wistore.GetWorkItem(94);
WorkItemServer wiserver = ttpc.GetService<WorkItemServer>();
string tmppath = wiserver.DownloadFile(wi.Attachments[0].Id); //Change the number to download other attachments if there are more then one attachments for the specific work item. e.g: [1] to download the second one.
string filename = string.Format("D:\\WITAttachments\\{0}-{1}", wi.Fields["ID"].Value, wi.Attachments[0].Name);
File.Copy(tmppath, filename);
}
}
}
然后您可以尝试查询工作项并为每个工作项循环下载附件。参见 Fetch work items with queries programatically in VSTS了解详情。
以下示例供您引用:
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Proxy;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
using Microsoft.VisualStudio.Services.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
namespace DownloadWITAttachments
{
class Program
{
static void Main(string[] args)
{
Uri uri = new Uri("https://account.visualstudio.com");
string PAT = "xxxxxxxxxxxx";
string project = "ProjectName";
VssBasicCredential credentials = new VssBasicCredential("", PAT);
//create a wiql object and build our query
Wiql wiql = new Wiql()
{
Query = "Select * " +
"From WorkItems " +
"Where [Work Item Type] = 'User Story' " +
"And [System.TeamProject] = '" + project + "' " +
"And [System.State] <> 'Closed' " +
"And [System.AttachedFileCount] > 0 " +
"Order By [State] Asc, [Changed Date] Desc"
};
//create instance of work item tracking http client
using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(uri, credentials))
{
//execute the query to get the list of work items in the results
WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql).Result;
if (workItemQueryResult.WorkItems.Count() != 0)
{
//Download the first attachment for each work item.
foreach (var item in workItemQueryResult.WorkItems)
{
TfsTeamProjectCollection ttpc = new TfsTeamProjectCollection(uri);
ttpc.EnsureAuthenticated();
WorkItemStore wistore = ttpc.GetService<WorkItemStore>();
Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem wi = wistore.GetWorkItem(item.Id);
WorkItemServer wiserver = ttpc.GetService<WorkItemServer>();
string tmppath = wiserver.DownloadFile(wi.Attachments[0].Id);
string filename = string.Format("D:\\temp\\vsts\\{0}-{1}", wi.Fields["ID"].Value, wi.Attachments[0].Name);
File.Copy(tmppath, filename);
}
}
}
}
}
}
关于c# - 如何在 Azure DevOps 中以编程方式下载附件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50119480/
我没有上传附件以使浏览器正常工作。 一些提示是 here , 其他 there . The docs非常好,但我无法将其转换为 AJAX 上传。 我正在寻找一个 super 简单的 HTML/Java
我有一个应用程序可以收集一些信息并允许用户使用 Android 的 Intent 框架共享这些信息。 到目前为止,它以纯文本形式共享报告:使用 putExtra(Intent.EXTRA_TEXT,
我正在尝试通过我的应用程序发布带有附件图片的消息,所以我使用了以下代码: function yamPost(mytoken) { var msg_Body = jQuery("#myB
我在用户表中使用了多对多关系来使登录用户关注另一个用户,但我自己没有弄清楚,我检查了其他人做了什么,并尝试做类似的事情,并且它有效。在我的方法中,我有: function follow(User $u
我正在用 PHP 创建脚本,其作用是将 IMAP 服务器备份到 MySQL 数据库。 我现在的问题是: 如果电子邮件有附件,附件是嵌入在电子邮件本身中还是服务器上的一个单独文件? 我问的原因是: 我可
我正在使用 RavenDB,在我处理任何附件之前删除了一些带有附件的测试文档,所以我在想它们是否还在磁盘上的某个地方,以及如何轻松地找到它们?。 另一个问题是:当文档被删除时,它有一个附件,附件会被自
当您使用 ACTION_SEND Intent (使用额外的 EXTRA_STREAM)将文件附加到电子邮件时,电子邮件应用程序是否将该附加文件复制到它自己的位置?我的应用程序创建了一个文件并将其附加
所以: // Setup mail class, recipients and body $mailer->AddAttachment('/home/mywebsite/public_html/fil
您好,我需要一个 DnD 解决方案来将 Outlook 邮件附件拖到 Stackpane。 JavaFX/展望 2010 stackpaneDragAndDropZone.setOnDragO
我尝试制作一个 PhpSpreadsheet 文档,然后将他添加到邮件附件中。也许是太热了,但在 phpSpreadsheet 文档中几个小时后,我还没有找到任何东西。 这是我发送邮件的文件 $nam
有什么方法可以动画删除 UITableView 单元格附件吗? 我当前正在显示一个 UITableViewCellAccessoryDisclosureIndicator,但我想在所有可见表格单元格上
我正在编写一个 iPhone 应用程序,它要求我以编程方式发送电子邮件附件。附件是我通过代码创建的 csv 文件。然后,我将文件附加到电子邮件中,附件就会显示在手机上。但是,当我向自己发送电子邮件时,
我正在尝试通过收件箱中的名称“MacroEnabled”访问子文件夹,找到其中的所有附件并将它们保存到本地驱动器。 我使用此代码创建一个名为“Documents”的文件夹并保存附件。然而,在进行第二次
将 corda 升级到版本 4 后,我收到 net.corda.core.transactions.MissingContractAttachments:找不到 com.template.contra
我正在尝试让 Jenkins 将一个或一组文件附加到作业已完成的电子邮件通知中。我不断收到以下错误: 发送电子邮件以触发:成功错误:访问要附加的文件时出错:需要 Ant GLOB 模式,但看到 C:\
我创建了一个由来自 mysql 的数据填充的 UITableView(使用 NSJSONSERIALIZATION)。现在问题是一回事。我检索到的是产品名称。我想要一个附件 View (像单元格右侧的
我开发了一个 Java 客户端应用程序,用于下载我自己的电子邮件。我发现我无法在电子邮件中找到某些附件,特别是当我向经过认证的公司发送电子邮件时收到的作为收据的 XML 文件。我用于下载附件的代码:
我正在将我的 sqlite 数据库转换为 Couchdb。我可以转换数据库并上传到 Couchdb 服务器。除了图像之外的一切。我想将图像作为独立附件上传,我想使用 javascript、REST 和
我编写了一段代码,以便能够启动默认的电子邮件服务提供商,即我的 Outlook。这是我的代码: if(role.getValue().equals("1")) { Desktop desktop =
我正在尝试使用链接上共享的代码使用 python 从 Gmail 下载电子邮件附件 https://gist.github.com/baali/2633554 我想应用时间过滤器+主题过滤器并下载附件
我是一名优秀的程序员,十分优秀!