问题
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