tags:

views:

52

answers:

3

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 title 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?

+1  A: 
F.Aquino
+2  A: 

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

ArjanP
In theory your suggestion sounds plausable, but this is SharePoint we're talking about, so I will have to really test it to make sure it respects that property.
JL
LOL.. let go, let go.. embrace The SharePoint
ArjanP
ok it worked... and without a prayer first....
JL
A: 

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
naivists