views:

267

answers:

1

Hello All,

Firstly, the simple question - has anyone had any experience programmatically renaming/moving a folder in a directory structure in SharePoint?

The background:

I have inherited some work, and am in the throws of fixing a few defects in it. For the most part things are going well, but there is one issue that I am banging my head against the wall on.

The application is an ASP.NET web application (C#) with a SharePoint 3 document store. The application maintains a folder structure on the server, the names of the folder are dependant on data within the application and can be changed (in real time).

The current approach has been to use the FrontPage extensions to handle some of the requests to SharePoint, as documented here: http://msdn.microsoft.com/en-us/library/ms443099.aspx

Currently a folder will correctly be renamed if the folder does not exist, but if it does exist it will throw an error (and logically so). In this case we want to MOVE the contents of the folder into the existing folder. From the documentation I believe our approach should work...... but it doesn't, so I am hoping there is something that can be easily modified.

The code:

const string renameOption = "findbacklinks";
const string putOption = "overwrite,createdir,migrationsemantics";
string method = "method=move+document%3a12.0.4518.1016&service_name=%2f&oldUrl={0}&newUrl={1}&url_list=[]&rename_option={2}&put_option={3}&docopy={4}";

method = String.Format(method, oldUrl, newUrl, renameOption, putOption, bool.FalseString.ToLower());
// then submit and handle the request

I have tried modifying the above put options, and would have thought the above "overwrite" options would have prevented the error message we recieve, the guts of which is:

method=move document:12.0.0.6219
status=131097
osstatus=0
msg=Cannot rename value to value: destination already exists.

My preferred approach would be to get the above implementation to work, rather then a complete re-write using other techniques (although of course if there is a fundamental flaw in the above I understand a re-write may be needed).

From what research I have done it would appear this is a somewhat difficult task, and there are complexities in any approach?

Thanks Chris

+1  A: 

I believe that the move document method only works within the same list and isn't for moving between locations. It should really be called rename document. This would explain why you are receiving the 'destination already exists' error.

It appears that the company HubKey have developed a free beta library available that does this if you read the comments to this post.

Personally, I would develop a custom web service that does this (in fact I don't think I'd use the RPC stuff at all). Is this an option for you?

Alex Angas