tags:

views:

43

answers:

2

Hi all:

I was wondering whether it is possible to programmatically change the name of an SPFolder after it has been created?

e.g.

foreach (SPFolder folder in list.RootFolder.SubFolders)
{
    if (folder.Name.Equals("blah"))
    {
        // set the name of the folder to something else
        folder.Name = "blah 2.0";
    }
}

Googling so far suggested that MoveTo is the only way of doing so. There are a lot of items inside the folder so I'm reluctant to moving it unless there is absolutely no other ways.

Thanks.

A: 

when you have an SPFolder object, you can do it like this:

folder.item["Title"] = "blah 2.0";
folder.item.SystemUpdate();'
naivists
@naivists: How does ["Title"] differ from ["Name"] or ["BaseName"]? And how would SystemUpdate() differ from Update()?
Scott Stafford
`Title` is the most popular field in SharePoint, since every content type has it. BaseName and Name are fields specific to folders or files, I believe.
naivists
SystemUpdate differs from the regular Update as it does not change the "Last modified" and "Modified by" values. Hence, this is the best way to change it from the code, if the change does not have a significant business value.
naivists
You can find a good reference of built-in field names here: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spbuiltinfieldid_members.aspx
naivists
A: 

I ended up using MoveTo as there was no other ways of doing this.

BeraCim