我正在使用ms图,以便将文件上传到文档库中。 我已经为大型文件实现了代码,并且可以正常工作 但我不知道如何设置“驱动器”的自定义列
这是我的代码。我玩过extraData,但没有成功。
任何想法?
谢谢
public static async Task<DriveItem> uploadFile()
{
Stream fileStream = new FileStream(@"C:\prueba\prueba2.xlsx", FileMode.Open);
DriveItem uploadedFile = null;
UploadSession uploadSession = null;
uploadSession = await objGraphServiceClient.Sites["SITE_ID"].Lists["LIST-ID"].Drive.Root.ItemWithPath("EISE_PRUEBA2.xlsx").CreateUploadSession().Request().PostAsync();
if (uploadSession != null)
{
// Chunk size must be divisible by 320KiB, our chunk size will be slightly more than 1MB
int maxSizeChunk = (320 * 1024 * 10) * 4;
ChunkedUploadProvider uploadProvider = new ChunkedUploadProvider(uploadSession, objGraphServiceClient, fileStream, maxSizeChunk);
var chunkRequests = uploadProvider.GetUploadChunkRequests();
var exceptions = new List<Exception>();
var readBuffer = new byte[maxSizeChunk];
foreach (var request in chunkRequests)
{
var result = await uploadProvider.GetChunkRequestResponseAsync(request, readBuffer, exceptions);
if (result.UploadSucceeded)
{
uploadedFile = result.ItemResponse;
var uno = uploadedFile.AdditionalData;
var add = new Dictionary<string, object>();
add.Add("PositionCode", "Pos-01-" + DateTime.Now.ToString("mmmm"));
add.Add("Category", "Category_" + DateTime.Now.ToString("mmmm"));
var temp = new ListItem();
temp.Id = uploadedFile.Id;
temp.Fields = new FieldValueSet();
temp.Fields.AdditionalData = add;
var driveItem = new DriveItem();
//var users = await objGraphServiceClient.Users.Request().GetAsync();
// var driveItem = new DriveItem
// {
// Name = "new-file-name.xlsx"
// };
// //driveItem.CreatedByUser = users.First();
// driveItem.AdditionalData = new Dictionary<string, object>();
// driveItem.AdditionalData.Add(new KeyValuePair<string, object>("@odata.category", "Category" + DateTime.Now.ToString("mmmm")));
// driveItem.AdditionalData.Add(new KeyValuePair<string, object>("@odata.PositionCode", "Pos-01-" + DateTime.Now.ToString("mmmm")));
// var updatedItem = await objGraphServiceClient.Sites["hispaniaassetmanagement.sharepoint.com,d04053f4-eb19-4ed8-9785-0f7aa2a908c8,6227bfe6-c7cb-4990-8f51-0a7fd8c28c1b"].Lists["67987e61-86cc-4f3e-93f2-0b6699b97a94"].Drive.Items[uploadedFile.Id].Request().UpdateAsync(driveItem);
//objGraphServiceClient.Sites["hispaniaassetmanagement.sharepoint.com,d04053f4-eb19-4ed8-9785-0f7aa2a908c8,6227bfe6-c7cb-4990-8f51-0a7fd8c28c1b"].Lists["67987e61-86cc-4f3e-93f2-0b6699b97a94"].Drive.Items["017ZCPK2DMW4ZEXUK7QZHJ7CQLPY7GHDFJ"]
uploadedFile.ListItem.Fields.AdditionalData = add;
var updatedItem = await objGraphServiceClient.Sites["SITE-ID"].Lists["LIST-ID"].Drive.List.Items[uploadedFile.Id].Request().UpdateAsync(uploadedFile.ListItem);
}
}
}
return (uploadedFile);
}
答案 0 :(得分:0)
我在SDK中使用其余的API找到了解决方案。 使用图资源管理器将是:
匹配:https://graph.microsoft.com/v1.0/sites/ {siteID} / lists / {ListId} / items / {ItemId} / fields
内容类型:application / json
{ “ customColumn”:“值” }
但是!!!如果您要更新返回驱动器项的上载文件的文件,解决方案将是
var result = await uploadProvider.GetChunkRequestResponseAsync(request, readBuffer, exceptions);
if (result.UploadSucceeded)
{
uploadedFile = result.ItemResponse;
string webApiUrl = "https://graph.microsoft.com/v1.0/sites/"+ siteIDDMS + "/drives/"+driveIDHAMSLib+"/items/"+uploadedFile.Id+"/listItem/fields";
JObject paramsJson = new JObject()
{
["Category"] = "NewCat_" + DateTime.Now.ToString("mmmm")
};
await RunRestApi(webApiUrl, accessToken, paramsJson,"PATCH", Display);
}
顺便说一句...有人知道使用SDK能否实现?