How to find the folder URL to use with SPFile.MoveTo(string)

The folder URL is in the RootFolder parameter that you see in the address bar when you are viewing the folder. This is counterintuitive to me, because the SPList.RootFolder object will give you exactly that, the root folder, whereas the RootFolder parameter gives you a site-relative URL of the current folder. So the example code in MSDN on SPFile.MoveTo seems to be incorrect. To successfully move files from the actual root folder of a list to another folder within that list, I took the RootFolder parameter and decoded the escaped characters, and concatenated the filename (SPFile.Name) to the folder URL. So it was something like files[i].MoveTo("/Corp/Depts/ThisDept/ThisFolder/" + files[i].Name); See the MSDN code example for the rest.

Advertisement

About Dan Parker

SharePoint Developer since 2007. Born and raised in northern California, and moved to Houston in 2006. Always looking to improve my skills in SharePoint and .NET development.

Posted on January 12, 2012, in .NET, SharePoint. Bookmark the permalink. Leave a Comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.