我正在使用 ms graph 将文件上传到文档库中。我已经为大文件实现了一个代码,它可以工作,但我不知道如何设置“驱动器”的自定义列
这是我的代码。我玩过附加数据,但没有成功。
任何想法??
谢谢
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);
}