cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We are making some updates so the Community might be down for a few hours on Monday the 11th of November. Apologies for the inconvenience and thank you for your patience. You can find out more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Renaming a file is creating a copy in dropbox .NET SDK

Renaming a file is creating a copy in dropbox .NET SDK

SuryaMopuru
Explorer | Level 3

When i try to rename file i see in dropbox a copy being created rather than just a name change.

 

This is how i am trying to achieve this:

using (var dbx = new DropboxClient(RefreshToken,Appkey,Appsecret))
{
var updated = await dbx.Files.UploadAsync(
"/" + remoteUrl,
mode:WriteMode.Overwrite.Instance,
body: fileStream);

remoteUrl: dropbox folder path. Ex: /Backup/Notes/

I have specified writemode as overwrite but still a duplicate is getting created rather than just renaming. Is there any way to handle this?

 

 

3 Replies 3

Greg-DB
Dropbox Staff

The UploadAsync method is for uploading a file (whether a new file or a new version of an existing file). If you want to rename an existing file you should use MoveV2Async instead. That takes a fromPath for the existing path (including file name) of the existing file to move or rename, and toPath for the new path (including file name) that you want the file to have instead.

SuryaMopuru
Explorer | Level 3

How can i distinguish between rename and duplicate. Currently this is how i am trying to do:

 using (var dbx = new DropboxClient(RefreshToken, Appkey, Appsecret))
{
try
{
var metadata = (await dbx.Files.GetMetadataAsync("/" + backupItem.Path));
if (metadata != null)
{
var remote = "/" + remoteUrl;
var fromPath = "/" + backupItem.Path;
RelocationResult result = await dbx.Files.MoveV2Async(fromPath, remote);
if(result != null)
{
var updated = await dbx.Files.UploadAsync(
"/" + remoteUrl,
mode: WriteMode.Overwrite.Instance,
body: fileStream);
}
}
}
catch
{
var updated = await dbx.Files.UploadAsync(
"/" + remoteUrl,
mode: WriteMode.Overwrite.Instance,
body: fileStream);

 

When i try to rename it is working because moveasync will get invoked but when i try to duplicate the file it is updating the existing file rather than duplicating it. Do we have any way to handle my scenario.

For the first time when user creates any file our GetMetadatAsync will throw an error because in the mentioned path we dont have file so it goes into catch block and upload the new file.

This should happen in duplication also.

Greg-DB
Dropbox Staff

I see you also opened a new thread for this, so I'll follow up with you there.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    SuryaMopuru Explorer | Level 3
What do Dropbox user levels mean?