Export (0) Print
Expand All

SPFolder.MoveTo Method

Moves the folder and its contents to a new folder at the specified URL.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

public void MoveTo(
	string strNewUrl
)

Parameters

strNewUrl
Type: System.String

A string that specifies the URL for the new folder.

The MoveTo method applies only to the context of a single site.

The following code example moves a specified subfolder in the site from one folder into another folder.

SPWeb oWebsite = SPContext.Current.Web;
if (oWebsite.GetFolder("Shared Documents/Source_Subfolder_Name").Exists)
{
    SPFolder oFolderSrc = oWebsite.GetFolder("Shared Documents/Source_Subfolder_Name");

    oFolderSrc.MoveTo("DocLib_Name/Destination_Subfolder_Name");
}
Show:
© 2015 Microsoft