以编程方式更改共享点列表的名称

时间:2012-06-01 07:05:26

标签: c# sharepoint-2010

我正在尝试更改sharepoint文档库(不是标题)的“名称”。我找到了一种从sharepoint设计师那里做到的方法:http://www.thesharepointblog.net/Lists/Posts/Post.aspx?List=815f255a-d0ef-4258-be2a-28487dc9975c&ID=52我需要的是以程序化的方式完成这项工作。我怎么做?

1 个答案:

答案 0 :(得分:1)

“名称”是列表的实际根文件夹。所以你需要重命名它

            using (SPSite mySite = new SPSite("http://server"))
            {
                //open the relevant site
                using (SPWeb myWeb = mySite.OpenWeb("TestSite"))
                {
                    //loop through the lists
                    foreach (SPList list in myWeb.Lists)
                    {
                        //when we find the correct list, change the name
                        if (list.RootFolder.Name == "OrigListName")
                        {
                            //move the root folder
                            list.RootFolder.MoveTo(list.RootFolder.Url.Replace("OrigListName", "OrigListName_New"));
                        }
                    }
                }
            }