Use of SPListCollection.Add

1.5k views Asked by At

Can anybody tell me how to use the SPListCollection.Add(String, String, String, String, Int32, String, String, SPFeatureDefinition, SPListTemplate.QuickLaunchOptions) Method?

  • What is the purpose of the featureId parameter?
  • What is the purpose of the listInstanceFeatureDefinition parameter?
  • Which parameters are optional/required?
  • What is the format of the url parameter?

Thanks in advance!

2

There are 2 answers

0
Sandeep On

While the link you gave for MSDN clearly explain each parameter, here some example on how u can use it

http://spcore.codeplex.com/SourceControl/changeset/view/62542#1079698

1
Brian On

Keep running into that same codeplex link...not very helpful for this particular implementation of the method. After some trial and error, I did get this one working and it did get around the "invalid list template" error when trying to create lists from a custom content type (ie BaseTemplate > 100000). The function takes a SPList definition(ListToCopy) from one SPWeb and copies it to another SPWeb (NewWeb). The only missing link right now is the last parameter, docTemplateType, which I was forced to specify manually (101 - MS Word). Not sure how to get that one from the source list.

public static Guid CopyListDefToAWeb(String SourceWebUrl, SPList ListToCopy, SPWeb NewWeb)
    {
        Guid newListGuid = Guid.Empty;
        if (Convert.ToInt32(ListToCopy.BaseTemplate) < 10000)
        {
            newListGuid = NewWeb.Lists.Add(ListToCopy.Title, ListToCopy.Description, ListToCopy.BaseTemplate);
        }
        else
        {
            String newListUrl = ListToCopy.Title.Replace(" ", String.Empty);
            newListGuid = NewWeb.Lists.Add(ListToCopy.Title, ListToCopy.Description, newListUrl, ListToCopy.TemplateFeatureId.ToString(), Convert.ToInt32(ListToCopy.BaseTemplate), "101");
        }

        return newListGuid;
    }