如何使用c#将附件添加到Azure DevOps中的现有工作项 [英] How to Add attachments to an existing work item in Azure DevOps using c#
本文介绍了如何使用c#将附件添加到Azure DevOps中的现有工作项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请提供代码示例,说明如何使用C#向Azure DevOps中的现有工作项添加附件(文本文件和图像).
Would you please provide a code sample on how to add attachments (text file and an image) to an existing work item in Azure DevOps using C#.
推荐答案
Here are some blog and cases: 1 . 2 with C# code samples, you can refer to them.
using (FileStream attStream = new FileStream(FilePath, FileMode.Open, FileAccess.Read))
{
var att = WitClient.CreateAttachmentAsync(attStream, filePathSplit[filePathSplit.Length – 1]).Result; // upload the file
JsonPatchDocument patchDocument = new JsonPatchDocument();
patchDocument.Add(new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/relations/-",
Value = new
{
rel = "AttachedFile",
url = att.Url,
attributes = new { comment = "Comments for the file " + filePathSplit[filePathSplit.Length – 1] }
}
});
}
这篇关于如何使用c#将附件添加到Azure DevOps中的现有工作项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文