Skip to main content
Question

.NET SDK - upload file with versioning

  • May 22, 2025
  • 2 replies
  • 30 views

Forum|alt.badge.img

Using the Box .NET SDK.

 

Am I doing this correctly?  I want to upload a file and if it already exists in the account, upload a new version.  I'm doing a "preflight check" to see if the file already exists.  If it doesn't, I can just upload the file.  If it does exist, then I get the BoxFile.Id of the existing file and use that in my BoxFileRequest.  My assumption is including the file Id, Box will assume I want a new version.

 

BoxFileRequest request = new BoxFileRequest()
{
    Name = fileName,
    Parent = new BoxRequestEntity() { Id = boxFolderId },
    Id = fileId
};

result = await this._boxClient.FilesManager.UploadAsync(request, stream);

However -- I'm still getting a "file name in use" exception.  Am I doing something wrong or is the problem I'm using a free Developer account and maybe versioning is not allowed.  Also, I'm uploading the exact file again with no changes.

 

If you need more info, please let me know.  Thanks!

2 replies

Forum|alt.badge.img

 Upload File and Upload File Version are implemented as different methods in the .NET SDK. Here's the method in the .NET SDK to upload a new file version. There shouldn't be any restrictions for a developer account to use the file version endpoint. 


Forum|alt.badge.img

Aha!  I now see where I was going wrong.  I was building another BoxFileRequest and only FilesManager.UploadAsync needed that.  The FilesManager.UploadNewerVersionAsync just needs the file name, file ID, and the file contents as a stream (as a minimum), but no request.

 

Thanks much!