In this post I would like to share some of my findings that can help you while working in SharePoint Localized Environment.
item[SPBuiltInFieldId.Title] = "Some title";
1. Use SPListTemplateType while creating lists programmatically
Don’t use this line of code when creating list programmatically:
//WRONG: In SharePoint Localized Environment
Guid guid = web.Lists.Add(listName, String.Empty, web.ListTemplates["Document"]);
Simply because “Document” list template might be called “Документ” in a localized environment. Instead, better use this one:
//CORRECT: In SharePoint Localized Environment
Guid guid = web.Lists.Add(listName, String.Empty, SPListTemplateType.DocumentLibrary);
//WRONG: In SharePoint Localized Environment
Guid guid = web.Lists.Add(listName, String.Empty, web.ListTemplates["Document"]);
Simply because “Document” list template might be called “Документ” in a localized environment. Instead, better use this one:
//CORRECT: In SharePoint Localized Environment
Guid guid = web.Lists.Add(listName, String.Empty, SPListTemplateType.DocumentLibrary);
2. Use “SPBuiltInContentTypeId” enumerator
When working with build-in content types, use "SPBuiltInContentTypeId" enumerator to get them. Don’t rely on display name, in a localized environment this will not work
3. Use "SPBuiltInFieldId" enumerator for system fields:
If you want to access built-in "Title" field in a localized environment, and you do something like this:
item["Title"] = "Some title";
You may end up with this error:
System.ArgumentException: Value does not fall within the expected range.
at Microsoft.SharePoint.SPFieldCollection.GetFieldByDisplayName(String strDisplayName, Boolean bThrowException)
This is why SharePoint team gives us "SPBuiltInFieldId" enumerator which can be used to access all built-in fields by GUID. So, the above line will look like this:
item["Title"] = "Some title";
You may end up with this error:
System.ArgumentException: Value does not fall within the expected range.
at Microsoft.SharePoint.SPFieldCollection.GetFieldByDisplayName(String strDisplayName, Boolean bThrowException)
This is why SharePoint team gives us "SPBuiltInFieldId" enumerator which can be used to access all built-in fields by GUID. So, the above line will look like this:
item[SPBuiltInFieldId.Title] = "Some title";
:) Happy Coding!
No comments:
Post a Comment