如何使用 C# 将附件添加到 Azure DevOps 中的现有工作项

How to Add attachments to an existing work item in Azure DevOps using c#

能否提供一个代码示例,说明如何使用 C# 将附件(文本文件和图像)添加到 Azure DevOps 中的现有工作项。

这里有一些blog and cases: . 2的C#代码示例,大家可以参考一下。

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

    var workItem = UpdateWorkItemAsync(patchDocument, workItemId).Result;
}