Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IFile.MoveToAsync(string, MoveOperations = MoveOperations.None, MoveCopyOptions = null) could be changed #989

Closed
1 task done
ionbesleaga opened this issue Oct 10, 2022 · 5 comments
Assignees
Labels
area: model 📐 Related to the core SDK models bug Something isn't working

Comments

@ionbesleaga
Copy link

Category

  • Feature request

Describe the feature

The implementation of IFile.MoveToAsync() and IFile.MoveToBatchAsync() is calling a private method:

private ApiCall GetMoveToApiCall(string destinationUrl, MoveOperations moveOperations, MoveCopyOptions options)
{
    // If same site
    if (UrlUtility.IsSameSite(PnPContext.Uri, destinationUrl))
    {
        return GetMoveToSameSiteApiCall(destinationUrl, moveOperations);
    }
    else
    {
        bool overwrite = moveOperations.HasFlag(MoveOperations.Overwrite);
        options ??= new MoveCopyOptions() { KeepBoth = !overwrite };
        return GetMoveToCrossSiteApiCall(destinationUrl, overwrite, options);
    }
}

The issue is that it takes the optional MoveCopyOptions parameter into account only when the moving is done from one site to a different one: UrlUtility.IsSameSite() == false.
I was specifying the MoveCopyOptions.KeepBoth = true moving files on same SharePoint site, and it was ignored, overriding the file if it was already there.

Describe the solution you'd like

If it's possible to add the MoveCopyOptions parameter to GetMoveToSameSiteApiCall() and use it so we can keep both files when moving them across same site (preferably).

Another way for this could be to add separate IFile.MoveToAsync() and IFile.MoveToBatchAsync() for internal and external operations:

  • IFile.MoveToAsync(string, MoveOperations = MoveOperations.None)
  • IFile.CrossSiteMoveToAsync(string, MoveOperations = MoveOperations.None, MoveCopyOptions = null)
  • IFile.MoveToBatchAsync(Batch, string, MoveOperations = MoveOperations.None)
  • IFile.CrossSiteMoveToBatchAsync(Batch, string, MoveOperations = MoveOperations.None, MoveCopyOptions = null)
@jansenbe jansenbe self-assigned this Oct 10, 2022
@jansenbe
Copy link
Contributor

@IllBarto : good catch, we'll fix this.

@jansenbe jansenbe added bug Something isn't working area: model 📐 Related to the core SDK models labels Oct 11, 2022
@jansenbe
Copy link
Contributor

Notes: more alignment between MoveOperations and MoveCopyOptions is needed. Verify the behaviour of not setting MoveOperations.Overwrite.

@ionbesleaga
Copy link
Author

As a side note, you can keep both files on same site calling IFile.MoveToBatchAsync(destinationUrl, MoveOperations.Overwrite | MoveOperations.None). In this case MoveOperations.Overwrite | MoveOperations.None behaves like MoveCopyOptions.KeepBoth, but not sure what will happen when you'll add other MoveOperations flags.

jansenbe added a commit that referenced this issue Feb 13, 2023
…tions` and optimized file copy/move operations to use the cross site API as much as possible #989 #1091
@jansenbe
Copy link
Contributor

@IllBarto : Now most move operations use the same API (the cross site one) and solving your need of KeepBoth when the target already exists. Only when the MoveOperations.AllowBrokenThickets or MoveOperations.BypassApprovePermission are used the "old" API is used. Closing this one, please open a new issue if things are not working as expected.

@jansenbe
Copy link
Contributor

@IllBarto : this will be part of the upcoming nightly release (version 1.8.100 or higher)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: model 📐 Related to the core SDK models bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants