Problem

Recently, I caught the following error in a piece of code that was trying to move a document between two SharePoint document libraries inside the same SharePoint site (SPWeb):

“Value does not fall within the expected range”

Cause

The error was being throwned because an absolute URL was being specified as the destination URL in the SPFile.MoveTo method.

Solution

According to the MSDN article at http://msdn.microsoft.com/en-us/library/ms468280.aspx, we have:

public void MoveTo(
	string newUrl
)

The newUrl parameter in the SPFile.MoveTo method specifies the destination URL. As explained in the article, the SPFile.Moveto can only be used to move files inside the same SharePoint site (SPWeb) and so relative URLs should be used. Example:

Related Articles

To learn why your business should migrate to SharePoint Online and Office 365, click here and here.

If you want to convert your tenant’s root classic site into a modern SharePoint site, click here.

If you or your customers are not ready to move entirely to the Cloud and Office 365, a hybrid scenario could be an interesting scenario and SharePoint 2019 RTM was recently announced with improved hybrid support! To learn all about SharePoint 2019 and all its features, click here.

If you are a SharePoint administrator or a SharePoint developer who wants to learn more about how to install a SharePoint 2019 farm in an automated way using PowerShell, I invite you to click here and here.

If SharePoint 2019 is still not an option, you can learn more about how to install a SharePoint 2016 farm in an automated way using PowerShell, click here and here.

If you want to learn how to upgrade a SharePoint 2013 farm to SharePoint 2019, click here and here.

If you want to learn all the steps and precautions necessary to successfully keep your SharePoint farm updated and be ready to start your move to the cloud, click here.

If you learn how to greatly speed up your SharePoint farm update process to ensure your SharePoint farm keeps updated and you stay one step closer to start your move to the cloud, click here.

If you want to learn how to upgrade a SharePoint 2010 farm to SharePoint 2016, click here and here.

If you are new to SharePoint and Office 365 and want to learn all about it, take a look at these learning resources.

If you are work in a large organization who is using Office 365 or thinking to move to Office 365 and is considering between a single or multiple Office 365 tenants, I invite you to read this article.

If you want to know all about the latest SharePoint and Office 365 announcements from SharePoint Conference 2019, click here and here.

Happy SharePointing!

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here