azure-devops - 从 Sql Server varbinary 字段向 Azure DevOps 添加附件
问题描述
有没有办法从 SQL SERVER 获取 VARBINARY 字段并使用 C# 将其附加到 Azure DevOps 中的现有错误?
解决方案
使用 C# 和 ADO.NET,您可以将 SQL Server 数据库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;
推荐阅读
- python - 为什么 Python OpenCV 代码显示错误“NoneType”对象没有属性“__getitem__”?
- r - 用套索回归预测函数
- visual-c++ - 如何在 mFC VC++ 中将编辑控件的背景转换为透明?
- react-native - 应用程序退出后点击反应原生的android?
- python - 在 python 3 中更改更多字符
- react-native - REACT_NATIVE_MACOS - 错误:100000f7:SSL 例程:OPENSSL_internal:WRONG_VERSION_NUMBER
- python - 尝试读取 docx 文件时出现 UnicodeDecodeError
- openshift - 迁移 Nexus 存储库数据
- excel - Sumif 返回相同的值
- python - 精灵没有在 Pygame 中显示