views:

87

answers:

1

I have tried this:

SPFolder folder = ...;
folder.Item["Name"] = newName;
folder.Item.Update();

And it behaves mysteriously. If I run it, it throws an exception:

 SPException: Cannot complete this action.

HOWEVER, if I stop it in the debugger after the new Name assignment and before the Update(), and look at the properties of folder.Item, then continue, it works every time. It's not a timing thing, I tried stopping it in the debugger without looking at it in the Locals window, but it threw an exception that time.

This question indicates a similar solution but using SystemUpdate(), does that matter? http://stackoverflow.com/questions/3632389/programmatically-changing-name-of-spfolder

+1  A: 

You do not need to change the name, but te title. So:

folder.Item[SPBuiltInFieldId.Title] = newName;
folder.Item.Update(); // or SystemUpdate(false)

The difference between Update and SystemUpdate is that Update will change modified / modified by information and if versioning is enabled it will increase the version number. SystemUpdate does not update these.

Also note that I use SPBuiltInFieldId.Title. This is better than using "Title", because "Title" may cause issues in sites that are not in English.

Tom Vervoort
Sorry, I didn't see that it was for SharePoint 2003. I don't have any experience in 2003, only 2007 and 2010. It may work like this, but I'm not sure.
Tom Vervoort