SharePoint: How do you reference a localized list?
I have a SharePoint list that gets installed by a feature.
I need to enable content types which I do so in a feature receiver:
SPList list = site.Lists["NameOfList"];
list.ContentTypesEnabled = true;
list.Update();
The problem is that it seems the method:site.Lists["NameOfList"], is really looking at the Title not the ID.
How can I get the list by using the ID and NOT the titl开发者_JS百科e which is subject to change because of Localization...
<ListInstance
TemplateType="10051"
Id="ThisISTheIDField" //Want to retrieve list instance based on this field.
Title="$Resources:MyFile,MyResourceName;"
Url="Lists/URLOFList"
OnQuickLaunch="TRUE">
</ListInstance>
Thanks in advance. And 10 years of hail Maries for the MS SharePoint developer who wrote this internal dare I say - c.r.a.p?
So your list is a custom list, right?
You can add:
EnableContentTypes=TRUE
To your list definition and you won't need the feature?
See: List Element
There is no site.Lists (Maybe is a SPWeb? The naming is awkward, I Know)
<SPWeb Instance>.Lists.GetList(Guid uniqueId, bool bFetchMetadata)
<SPWeb Instance>.Lists.GetList(Guid uniqueId, bool bFetchMetadata, bool bFetchSecurityData)
<SPWeb Instance>.GetList(string strUrl)
The third option could combine the url and use the internal name to grab it (in the URL lists are accessed by the internal name)
If the operation has to be completed only once in a lifetime, I'd suggest looping throuhg the .Lists collection and checking if the baseTemplate matches:
For Each oList In web.Lists
If (list1.BaseTemplate = 10051) Then
oList.ContentTypesEnabled=True
End If
Next
精彩评论