Skip to main content
Question

C# Boxv2 API get file size failed

  • May 22, 2025
  • 3 replies
  • 22 views

Forum|alt.badge.img

I 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;
}

3 replies

Forum|alt.badge.img

 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);

Forum|alt.badge.img

It works. Many thanks for your help. : D

 

 


Forum|alt.badge.img

This does not appear to work in the .Net Core version of the SDK.  Following the same steps, every field except Type and Id are null.  

 

Is there a different method with the .Net Core SDK?

 

Thanks