从 Sql Server varbinary 字段向 Azure DevOps 添加附件
Add attachment to Azure DevOps from Sql Server varbinary field
是否可以使用 C# 从 SQL 服务器获取 VARBINARY 字段并将其附加到 Azure DevOps 中的现有错误?
添加到bug工作项的附件是在本地添加的,所以我觉得你应该先把varbinary数据下载到本地,然后作为附件添加到bug工作项。
关于从sql服务器下载varbinary数据,可以参考这个case或者通过Google.
关于使用C#给工作项添加附件,可以参考之前创建的
使用 C# 和 ADO.NET,您可以读取 SQL 服务器数据库 varbinary
字段值到 byte[]
,然后您可以使用 byte[]
创建流]
Stream stream = new MemoryStream(byteArray);
之后,您可以像这样将此数据作为附件上传到工作项(例如错误)(1111
是工作项 ID,test.pptx
只是一个示例,您应该得到它也来自数据库)
.....//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;
是否可以使用 C# 从 SQL 服务器获取 VARBINARY 字段并将其附加到 Azure DevOps 中的现有错误?
添加到bug工作项的附件是在本地添加的,所以我觉得你应该先把varbinary数据下载到本地,然后作为附件添加到bug工作项。
关于从sql服务器下载varbinary数据,可以参考这个case或者通过Google.
关于使用C#给工作项添加附件,可以参考之前创建的
使用 C# 和 ADO.NET,您可以读取 SQL 服务器数据库 varbinary
字段值到 byte[]
,然后您可以使用 byte[]
创建流]
Stream stream = new MemoryStream(byteArray);
之后,您可以像这样将此数据作为附件上传到工作项(例如错误)(1111
是工作项 ID,test.pptx
只是一个示例,您应该得到它也来自数据库)
.....//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;