Is there a way to get a VARBINARY field from SQL SERVER and attach it to an existing bug in Azure DevOps using C#?
2 Answers
The attachments added to the bug work item are added locally, so I think you should first download the varbinary data to the local and then add it as an attachment to the bug work item.
About downloading varbinary data from sql server,you can refer to this case or through Google.
About adding attachments to an work item using C#,you can refer to the case you created earlier.

- 17,829
- 2
- 21
- 25
With C# and ADO.NET, you can read SQL Server database varbinary
field value to byte[]
, then you can create stream by using that byte[]
Stream stream = new MemoryStream(byteArray);
After that, you can upload this data as attachment to a work item (e.g. bug) like this (1111
is the work item id, test.pptx
is just a sample, you should get it from database too)
.....//ADO.NET to read varbinary field to byte[]
Stream stream = new MemoryStream(byteArray);
var u = new Uri("https://{org}.visualstudio.com");
VssCredentials c = new VssCredentials(new Microsoft.VisualStudio.Services.Common.VssBasicCredential(string.Empty, "personal access token"));
var connection = new VssConnection(u, c);
var workItemTracking = connection.GetClient<WorkItemTrackingHttpClient>();
JsonPatchDocument jsonPatchOperations = new JsonPatchDocument();
var attachmentresult = workItemTracking.CreateAttachmentAsync(stream,fileName:"test.pptx").Result;
jsonPatchOperations.Add(new JsonPatchOperation() {
Operation=Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Add,
Path= "/relations/-",
Value = new
{
rel="AttachedFile",
url=attachmentresult.Url,
attributes = new { comment = "Adding new attachment" }
}
});
var workitemupdated= workItemTracking.UpdateWorkItemAsync(jsonPatchOperations, 1111).Result;
The related references are in Microsoft.TeamFoundationServer.ExtendedClient package

- 33,174
- 2
- 29
- 53