Learn how to make the most out of the Dropbox Community here 💙. 

Forum Discussion

SuryaMopuru's avatar
SuryaMopuru
Explorer | Level 3
3 years ago
Solved

Distinguish between duplicating a file and renaming a file

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's avatar
    Greg-DB
    3 years ago

    I'm not sure I follow. Dropbox provides these API calls/methods for performing whatever operations the third party app (your app) needs to perform, but it's up to the third party app to build and show its UI to the end-user, allow them to perform actions and provide input, and use its logic to determine what calls to make and when. So, for example, the user may indicate in your app that they want to move a file, or make a copy of a file, and the app would use the corresponding method accordingly.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    As in your previous thread, 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. 

     

    Additionally, if you want to duplicate, that is, make a copy of, an existing file, you can use CopyV2Async instead. Similar to moving a file, that method takes a fromPath for the existing path (including file name) of the existing file you want to copy, and toPath for the new path (including file name) of where you want the new copy of the file to be put.

    • SuryaMopuru's avatar
      SuryaMopuru
      Explorer | Level 3
      Do we have any way to know that selected file is to duplicate or rename.

      Any id or something to know that user has choosen to duplicate the file or to renamw the file
      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        I'm not sure I follow. Dropbox provides these API calls/methods for performing whatever operations the third party app (your app) needs to perform, but it's up to the third party app to build and show its UI to the end-user, allow them to perform actions and provide input, and use its logic to determine what calls to make and when. So, for example, the user may indicate in your app that they want to move a file, or make a copy of a file, and the app would use the corresponding method accordingly.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,965 PostsLatest Activity: 2 hours ago
360 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!