SPList’s Title Property & SPField’s DisplayName not Updating
We encountered a problem which seemed really strange while provisioning our site collection with PowerShell (New-SPSite). Our provisioning contains programmatic custom list creation to our publishing webs via feature receivers. The procedure is that the feature receiver creates the list with a URL friendly Title and then changes the Title to a UI friendly version. Say, a list “orderform” is created and then the name of the list is changed to “Order Form” would result that we have a list “Order Form” at URL http://sharepointsite/lists/orderform.
What would you say if I told you that you can’t change the Title of a list after it is created with PowerShell or custom console app, if you are working with sites any other language than English. Well it’s true. I’ve tested it with two Team Sites, one in English and another in Swedish and by creating a generic list “Temp” to both of them. Then I tried the following PowerShell commands on both of the sites.
- $web = Get-SPWeb(“http://sharepointsite”)
- $list = $web.Lists[“Temp”]
- $list.Title = “Temp2”
- $list.Update()
The commands above update the “Temp” List’s Title to “Temp2″ when my $web is the English team site but nothing happens if I run the same commands to my Swedish site. First I run the PowerShell commands to the sites
Then I wonder why the Swedish site’s list title has not been updated…
…while the English site’s list title is updated as expected.
The resolution to the problem lies in the API. While trying to figure out what was going on by narrowing our use case which was a pretty large scale provision to the fact that you can’t edit list’s title even with PowerShell consisted of the following steps and remarks:
- The SPList SchemaXml property consists of a root element List, which has an attribute Title: the english site had Title=”Temp2″ while Swedish site had Title=”Temp” but the SchemaXmlInCurrentUiCulture property had a correct Title-attribute in the Swedish site’s case Title=”Temp2″
- After running IISRESET, the first page load in Swedish site’s /_layouts/viewlsts.aspx showed the updated Title “Temp2″ of the list but after that page loads resulted the Title being the original “Temp”
- While Googling, I came across this blog post by Vojtech Nadrovnik, which describes a similar problem but with SPField‘s DisplayName and the fact that Vojtech resolved the issue with reflection after first digging into the SharePoint code with a disassembler
- Following Vojtech’s example, I tried some disassembling myself with ILSpy and found out that there is a very similar condition in SPList’s Title property’s setter (the last if) as seen in Vojtech’s SPField case
Some properties ARE NOT updated if the Thread’s UI Culture IS NOT the same as the web’s UI Culture.
If you have a feature and a receiver which might be activated by some other means than from the UI (_layouts/ManageFeatures.aspx) or any other piece of code that might be run outside SharePoint’s context, you could handle the problems described above by changing the thread’s UI Culture to the web’s UI Culture programmatically and it would work in any language as the following sample illustrates (different from Vojtech’s resolution):
{
SPWeb web = properties.Feature.Parent as SPWeb;
string title = "Temp";
string displayName = "Temp2";
CultureInfo originalUICulture = Thread.CurrentThread.CurrentUICulture;
bool allowUnsafeUpdates = web.AllowUnsafeUpdates;
try
{
if (SPContext.Current == null)
{
// IF CURRENT THREAD'S UI CULTURE
// IS NOT THE SAME AS WEB'S UI CULTURE,
// STRANGE THINGS CAN HAPPEN
Thread.CurrentThread.CurrentUICulture =
new CultureInfo((int)web.Language);
}
web.AllowUnsafeUpdates = true;
// create list
Guid listId = web.Lists.Add(title, "",
SPListTemplateType.GenericList);
// get newly created list by id
SPList list = web.Lists[listId];
// change list's title
list.Title = displayName;
list.Update();
}
finally
{
web.AllowUnsafeUpdates = allowUnsafeUpdates;
if (SPContext.Current == null)
{
// TOGGLE THE UI CULTURE BACK
Thread.CurrentThread.CurrentUICulture =
originalUICulture;
}
}
}
Popularity: 5% [?]
This is actually documented on MSDN (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.title.aspx). TitleResource being the key word.
Here is a solution for changing Thread’s UI culture in PowerShell: http://blog.andersdissing.com/2011/07/change-powershell-ui-culture.html.
Thank you soooo much Juha! This fixed everything, even my missing field descriptions, which was unexpected!
Thank you very very much! You just saved me some headaches
Thank you soooo much for this. I don’t know what they were thinking when adding this validation.
[...] I found the solution in this blog: http://www.sharepointblues.com/2011/11/14/splist-title-property-spfield-displayname-property-not-upd... [...]
I don’t know how many days I’ve spent cursing over inconsistencies in how sharepoint deals with titles/displayname for fields and lists. The behavior I encountered made no sense, but having read this thread I’ll have to go through it again and see if I can make sense of it.
I see a lot of interesting content on your page. You
have to spend a lot of time writing, i know how to save you a lot
of work, there is a tool that creates unique, SEO friendly
articles in couple of minutes, just type in google –
k2 unlimited content
You post interesting content here. Your website deserves much more traffic.
It can go viral if you give it initial boost, i know very useful service that can help you, simply
type in google: svetsern traffic tips
Amazing ouyeah !
Hello Dear, are you in fact visiting this website on a regular basis, if so then you will definitely get good
knowledge.
Thanks for any other fantastic post. Where else may just anybody
get that type of info in such a perfect way of writing? I have a presentation next week, and I’m at the search for such information.
It’s awesome designed for me to have a web page, which is useful
in support of my know-how. thanks admin
[...] set the environment’s culture to the culture of the web as per this article but it seemed to have no effect. I tried setting an xml with updated displayname [...]
Problem solved. Thanks!
ブランドコピー品激安通販店
メンズ時計専門店をご覧頂き誠にありがとうございます。
豊富な品数を備えているほか、
その最新作品のコピー品を提供する一方。
超人気高級ウブロ・ロレックス・オメガ・フランクミュラー・カルティエ等提供ブランド時計専門店はお客様がご安心に購入
最高ランクの『スーパーコピー』
N級品のみを扱っており、取扱い販売をさせていただいております。スーパーコピーのスーパーコピー)のスーパーコピー販売
ホームページ上でのご注文は24時間受け付けております
Your way of putting things together is admirable. click here
Incredible post! I love to share this. Thanks |
Problem solved! Thanks love it
Encountered this problem as well but it’s now okay.
Thanks for the update. Glad to see no errors in my end. https://www.carpetcleanercolumbia.com
Thanks for posting an update, really appreciated.
Great site to comment, thanks for sharing always a nice blog here.
Glad you did it.
I always look up in this site for solutions. Thanks for resolving this problem!
Thanks for this solution! https://towingfallschurchva.com
Nice post! Thanks for sharing this solution.
Thanks for this information! Keep it up!
Great job, Juha! Keep it up! pestcontrolashburnva.com
The problem is that the DisplayName is not updated. If I use a tool like “SharePoint Manager 2010″.
Thanks for sharing, nice stuff.
Awesome post!
Nice article! Visit travesat for yor own sexy chat experience!
This has been useful for every person who encounter this issue. concrete contractors tuscaloosa al
Thanks for this great post.
Awesome article you shared.
Glad to check this site again.
Thanks for taking the time in sharing this great information.
This is a great article and this level of coding is a bit above my head but is written to be easily understood.
Thanks for sharing this great article.
Very interesting post!
Looking forward to more great posts here.
Great site to visit.
Very good article
This is really a great information, thanks for sharing.
Thanks for this post.
Informative post. Keep sharing.
http://bwoodplumber.com
Great work
plumer near me
Great content to share.
http://www.landscaperbirmingham.com
Great material
http://www.birminghamwindowcleaner.com