Azure devops 从Sql Server varbinary字段向Azure DevOps添加附件

Azure devops 从Sql Server varbinary字段向Azure DevOps添加附件,azure-devops,attachment,Azure Devops,Attachment,有没有办法从SQL SERVER获取VARBINARY字段,并使用C#将其附加到Azure DevOps中的现有bug?添加到bug工作项的附件是本地添加的,因此我认为您应该首先将VARBINARY数据下载到本地,然后将其作为附件添加到bug工作项 关于从SQLServer下载varbinary数据,您可以参考此内容或通过Google 关于使用C#向工作项添加附件,您可以参考前面创建的。使用C#和ADO.NET,您可以将SQL Server数据库varbinary字段值读取到字节[],然后您可以

有没有办法从SQL SERVER获取VARBINARY字段,并使用C#将其附加到Azure DevOps中的现有bug?

添加到bug工作项的附件是本地添加的,因此我认为您应该首先将VARBINARY数据下载到本地,然后将其作为附件添加到bug工作项

关于从SQLServer下载varbinary数据,您可以参考此内容或通过Google

关于使用C#向工作项添加附件,您可以参考前面创建的。

使用C#和ADO.NET,您可以将SQL Server数据库
varbinary
字段值读取到
字节[]
,然后您可以使用该
字节[]
创建流

Stream stream = new MemoryStream(byteArray);
之后,您可以像这样将此数据作为附件上载到工作项(例如bug)(
1111
是工作项id,
test.pptx
只是一个示例,您也应该从数据库中获取)

....//ADO.NET将varbinary字段读取到字节[]
流=新内存流(byteArray);
var u=新Uri(“https://{org}.visualstudio.com”);
VssCredentials c=新的VssCredentials(新的Microsoft.VisualStudio.Services.Common.VSSBasiccredentials(string.Empty,“个人访问令牌”);
var连接=新VSS连接(u,c);
var workItemTracking=connection.GetClient();
JsonPatchDocument jsonPatchOperations=新的JsonPatchDocument();
var attachmentresult=workItemTracking.CreateAttachmentAsync(流,文件名:“test.pptx”).Result;
添加(新的jsonPatchOperations(){
Operation=Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Add,
Path=“/relations/-”,
值=新
{
rel=“AttachedFile”,
url=attachmentresult.url,
attributes=new{comment=“添加新附件”}
}
});
var workitemupdated=workItemTracking.UpdateWorkItemAsync(jsonPatchOperations,1111);
相关参考资料在软件包中

.....//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;