Programmatically changing name of SPFolder

限于喜欢 提交于 2020-01-02 11:05:29

问题


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.


回答1:


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




回答2:


In a Document Library the field Name of an item (folder) has StaticName = FileLeafRef. So what really worked for me is

folder.Item[SPBuiltInFieldId.FileLeafRef] = "The new name";
folder.Item.Update();



回答3:


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

folder.item["Title"] = "blah 2.0";
folder.item.SystemUpdate();'


来源:https://stackoverflow.com/questions/3632389/programmatically-changing-name-of-spfolder

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!