1

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)
        {
            Console.WriteLine(ex);
            listItem.SystemUpdate(false);
        }

            fillArtistInformation();
    }

    public void fillArtistInformation()
    {
        using (SPSite siteCollection = new SPSite(fullURL))
        {
            SPWeb web = siteCollection.OpenWeb();
            System.Diagnostics.Debug.Write(web.Title);

            try
            {
                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;
                item.Update();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
            }
        }
    }
}
1
  • 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
1

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

or

  • 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.

Tim

0

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.