SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a parent site which creates child pages programmatically. They use a custom template with a List which I have created in VS. Now I want to access that list in C# from the parent site. I have tried it like the code part below but when I loop through all available lists it isn't there. My question is, how can I acccess the list. After debugging it fails when it looks for the ArtistInformation list.

            //Create website
            artistWeb.Webs.Add(artist, artist, artist, artistWeb.Language, webTemplate,     false, false);
        catch (Exception ex)


    public void fillArtistInformation()
        using (SPSite siteCollection = new SPSite(fullURL))
            SPWeb web = siteCollection.OpenWeb();

                SPList list = web.Lists["ArtistInformation"];
                SPListItem item = list.Items.Add();
                item["Title"] = artist;
                item["WorkAddress"] = address;
                item["WorkZip"] = zip;
                item["WorkCity"] = city;
                item["WorkCountry"] = country;
                item["Price"] = price;
            catch (Exception e)
share|improve this question
Can you provide XML definition of your element file? If you create your element.xml using visual studio - your list name is generated by VS... – Andrew Adamich Feb 22 '13 at 9:13
up vote 1 down vote accepted

Firstly, your SPWeb (which you've created using OpenWeb()) should be inside a using() construct.

The reason I suspect that you're not able to get the correct list is either because:

  • The name of the list is not "ArtistInformation", remember you must use the DISPLAY NAME of the list in this situation


  • fullURL does not have the actual URL of the created web within it. Since you haven't given us the context for that variable there is no way to tell if this is absolutely true, but I suspect that it is, in fact, the parent web's URL.


share|improve this answer
Your first solution fixed my problem. Thank you! – Fabian Blom Feb 22 '13 at 14:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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