So heres a conceptual question that I can't really find in any books. Is it possible to programmatically write to 2 different lists a the same time. I mean I think it is, but my code is not working which means it's probably a syntax error, if it's possible.

  • Provide code, and what do you mean at one time? – Sam Sussman Nov 9 '12 at 23:41
  • What thantos is getting at is do you mean literally in parallel via multiple threads or would a foreach operation writing the same item to each list one immediately after the other be acceptable? – Robert Kaucher Nov 10 '12 at 2:49
  • Will, could you edit this question to more accurately reflect the intent? It seems a lot of us thought you meant "writing to 2 different lists" to mean writing a list item to two different lists. – Robert Kaucher Nov 11 '12 at 1:59

By the description of your question I guess your talking about creating multiple lists using a single feature, if that's right then yes you can have multiple list definitions associated to a single feature but I wouldn't going to recommend this as it can lead to development issues in future.

but still if you want to go it then here's a simple example,

Your Feature file will look like this,

Title="Feature Multiple Lists" 
Description="Feature with three lists." 
Id="put a GUID in here" 
    <ElementManifest Location="elementfileA.xml" />
    <ElementManifest Location="elementfileB.xml" />
    <ElementManifest Location="elementfileC.xml" />

In above feature code I declared three elementmanifest with location to a element file, element.xml contains a definition for a feature element.

Now you can declare a elementfileA with a tag for ListTemplate,

<?xml version="1.0" encoding="utf-8"?>
<Elements Id="anotherGUID" xmlns="http://schemas.microsoft.com/sharepoint/">
  SecurityBits="11" />

you can create two more element files with respected names as you declared them in feature.xml, for the above listTemplate, make sure you create a new folder with same name as listtemplate e.g. in this case you will have three folders named as elementfileB, elementfileA or elementfileC with each list's schema.xml in them.

For more information on this you can look at this MSDN article

However if you want to add multiple lists using code then you can try something like this,

using (SPSite oSPsite = new SPSite("http://Web URL"))
    oSPsite.AllowUnsafeUpdates = true;

    using (SPWeb oSPWeb = oSPsite.OpenWeb())
        oSPWeb.AllowUnsafeUpdates = true;

        /* 1. create list from custom ListTemplate present within ListTemplateGalery */
        SPListTemplateCollection lstTemp = oSPsite.GetCustomListTemplates(oSPWeb);
        SPListTemplate template = lstTemp["custom template name"];
        oSPWeb.Lists.Add("List Name 1", "Description", template);

        /* 2. create list from sharepoint list content type (e.g. Links) */
        oSPWeb.Lists.Add("List Name 2", "Description", SPListTemplateType.Links);

        oSPWeb.AllowUnsafeUpdates = false;

    oSPsite.AllowUnsafeUpdates = false;

For more information on creating a list using check this Link out

I am no master so if you see any mistake let me know,

hope it helps :)

|improve this answer|||||

Please provide more information about effect you want to achieve, because I'm not sure if I understand you correctly.

Theoretically, it should be possible to write / update any number of lists at the same time, using for example parallel threads. You can simplify this as - threads as users. So, when 2 users can edit 2 different lists at the same time, why wouldn't it work on 2 threads?

Just make sure you called Update() method on list / web / or any object you updated. This method is critical, do not forget about it. @TimeToThine example is good, but is missing this information.

BTW. You can have as many as list you want in one feature.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.