昨天下午遇到的这个问题,共享以下。
问题重现:
Site Settings ->Site content types->List Content Types->Item->Columns->Title->Edit site column in new window->尝试把title(标题)改为不同文字(如:testTitle),再尝试改回时,会提示:The Column name that you entered is already in use or reserved,
解决办法:
第一步:把test改回到Title:
参考自:Content Types: Title Column Rename Issue
using(SPSite site = new SPSite("http://mssrv/"))
{
SPField f = site.RootWeb.Fields["testTitle"]
f.Title = args["Title"];
f.Update();
}
{
SPField f = site.RootWeb.Fields["testTitle"]
f.Title = args["Title"];
f.Update();
}
第二步:把所有站点的列表的field的testTitle改为Title
using (SPSite site = new SPSite("http://mssrv/"))
{
foreach(SPWeb web in site.AllWebs)
{
web.AllowUnsafeUpdates = true;
for(int i=0;i<web.Lists.Count;i++)
{
if (web.Lists[i].Fields.ContainsField("testTitle"))
{
SPField cfield = web.Lists[i].Fields.GetField("testTitle");
cfield.Title = "Title";
cfield.Update();
web.Lists[i].Update();
}
}
}
}
{
foreach(SPWeb web in site.AllWebs)
{
web.AllowUnsafeUpdates = true;
for(int i=0;i<web.Lists.Count;i++)
{
if (web.Lists[i].Fields.ContainsField("testTitle"))
{
SPField cfield = web.Lists[i].Fields.GetField("testTitle");
cfield.Title = "Title";
cfield.Update();
web.Lists[i].Update();
}
}
}
}