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

Added warning in the catch block #2888

Merged
merged 6 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `-OpenDocumentsMode` option to `Set-PnPList` which allows configuring if documents should be opened in the browser or in the local client [#2873](https://github.com/pnp/powershell/pull/2873)
- Added `-Properties` parameter to `Get-PnPUserProfileProperty` cmdlet which allows retrieval of specific properties if specified. [#2840](https://github.com/pnp/powershell/pull/2840)
- Added support for specifying the `-ContentUrl` configuration in `Add-PnPTeamsTab` cmdlet when trying to add a Planner as a tab in Teams channel. [#2850](https://github.com/pnp/powershell/pull/2850)
- Added support for `-Verbose` in `Move-PnPFile` which will show if it has problems determining if the destination location is a folder or a file [#2888](https://github.com/pnp/powershell/pull/2888)

### Changed

Expand Down Expand Up @@ -95,6 +96,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Contributors

- Chris R. [ChrisRo89]
- Aimery Thomas [a1mery]
- Ganesh Sanap [ganesh-sanap]
- Markus Hanisch [m-hanisch]
Expand Down
19 changes: 16 additions & 3 deletions documentation/Move-PnPFile.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Moves a file or folder to a different location
## SYNTAX

```powershell
Move-PnPFile [-SourceUrl] <String> [-TargetUrl] <String> [-Overwrite] [-AllowSchemaMismatch] [-AllowSmallerVersionLimitOnDestination] [-IgnoreVersionHistory] [-NoWait] [-Force] [-Connection <PnPConnection>]
Move-PnPFile [-SourceUrl] <String> [-TargetUrl] <String> [-Overwrite] [-AllowSchemaMismatch] [-AllowSmallerVersionLimitOnDestination] [-IgnoreVersionHistory] [-NoWait] [-Force] [-Connection <PnPConnection>] [-Verbose]
```

## DESCRIPTION
Expand Down Expand Up @@ -193,7 +193,20 @@ Accept pipeline input: False
Accept wildcard characters: False
```

## RELATED LINKS
### -Verbose
When provided, additional debug statements might be shown while executing the cmdlet.

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
```yaml
Type: SwitchParameter
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

## RELATED LINKS

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
15 changes: 8 additions & 7 deletions src/Commands/Files/MoveFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class MoveFile : PnPWebCmdlet
private const string ParameterSet_SERVER = "Server Relative";
private const string ParameterSet_SITE = "Site Relative";
private const string ParameterSet_OTHERSITE = "Other Site Collection";

[Parameter(Mandatory = true)]
[Alias("ServerRelativeUrl", "SiteRelativeUrl")]
public string SourceUrl = string.Empty;
Expand All @@ -38,7 +38,7 @@ public class MoveFile : PnPWebCmdlet
[Parameter(Mandatory = false)]
public SwitchParameter Force;

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false)]
public SwitchParameter NoWait;

protected override void ExecuteCmdlet()
Expand All @@ -64,9 +64,9 @@ protected override void ExecuteCmdlet()

Uri currentContextUri = new Uri(ClientContext.Url);
Uri sourceUri = new Uri(currentContextUri, EncodePath(sourceFolder));
Uri sourceWebUri = Microsoft.SharePoint.Client.Web.WebUrlFromFolderUrlDirect(ClientContext, sourceUri);
Uri sourceWebUri = Web.WebUrlFromFolderUrlDirect(ClientContext, sourceUri);
Uri targetUri = new Uri(currentContextUri, EncodePath(targetFolder));
Uri targetWebUri = Microsoft.SharePoint.Client.Web.WebUrlFromFolderUrlDirect(ClientContext, targetUri);
Uri targetWebUri = Web.WebUrlFromFolderUrlDirect(ClientContext, targetUri);

if (Force || ShouldContinue(string.Format(Resources.MoveFile0To1, SourceUrl, TargetUrl), Resources.Confirm))
{
Expand All @@ -83,23 +83,24 @@ protected override void ExecuteCmdlet()
var folderServerRelativePath = folder.EnsureProperty(f => f.ServerRelativePath);
isFolder = folderServerRelativePath.DecodedUrl == ResourcePath.FromDecodedUrl(TargetUrl).DecodedUrl;
}
catch
catch (Exception ex)
{
WriteVerbose($"Error occurred while trying to check if the target URL {TargetUrl} is a folder. This could happen if the target folder does not exist yet. It may still work well. Exception: {ex.Message}");
}
if (isFolder)
{
WriteVerbose($"Moving file or folder from {sourceUri} to {targetUri}");
Move(currentContextUri, sourceUri, targetUri, SourceUrl, TargetUrl, true);
}
else
{

WriteVerbose($"Moving file or folder from {SourceUrl} to {TargetUrl}");
var file = CurrentWeb.GetFileByServerRelativePath(ResourcePath.FromDecodedUrl(SourceUrl));
file.MoveToUsingPath(ResourcePath.FromDecodedUrl(TargetUrl), Overwrite ? MoveOperations.Overwrite : MoveOperations.None);
ClientContext.ExecuteQueryRetry();
}
}
}

}

private string EncodePath(string path)
Expand Down