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

£可爱£侵袭症+ 提交于 2019-12-13 20:58:42

问题


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#.


回答1:


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


来源:https://stackoverflow.com/questions/57189394/how-to-add-attachments-to-an-existing-work-item-in-azure-devops-using-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!