C# Boxv2 API get file size failed
AnsweredI am now developing a C# WPF application. And I found that I cannot get the file size. When I use File.Size.HasValue, it return false. But, I can get the filename and fileid successfully.
Can anyone help? Thank you.
The codes are shown below.
async Task ListRootFolder()
{
var items = await client.FoldersManager.GetFolderItemsAsync("0", 1000, autoPaginate: true);
var files = items.Entries.Where(i => i.Type == "file");
List tempNameList = new List();
List tempSizeList = new List();
List tempIdList = new List();
foreach (var file in files)
{
//*****BUG TO FIX*****
Console.WriteLine("boxfileSize:" + file.Size.HasValue.ToString());
tempNameList.Add(file.Name);
//*****BUG TO FIX*****
//tempSizeList.Add((float)file.Size);
tempIdList.Add(file.Id);
}
CloudFileInfo[] cloudFileInfos = new CloudFileInfo[tempNameList.Count];
for (int i = 0; i < cloudFileInfos.Length; i++)
{
cloudFileInfos[i].fileName = tempNameList[i];
cloudFileInfos[i].fileSize = 0;//*****BUG TO FIX***** //tempSizeList[i];
cloudFileInfos[i].fileId = tempIdList[i];
}
return cloudFileInfos;
}
-
When getting the items in a folder, the API only returns a limited set of fields for each item by default (which doesn't include size). You'll need to specifically request the fields you need if you want the size field returned, like this:
var fields = new List() { "type", "id", "name", "size" }; var items = await client.FoldersManager.GetFolderItemsAsync("0", 1000, autoPaginate: true, fields: fields);
Please sign in to leave a comment.
Comments
3 comments