Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Custom List Adding item in Parent/child

0 views
Skip to first unread message

Mr Buz

unread,
Dec 7, 2009, 9:13:01 PM12/7/09
to
Hi,

Im trying to write some code in c# to add parent and child items to a custom
list. I have the code successfully creating folder/parent level items but
how do I add child items to the parent items?

The list basically is a store for two levels of menu items. Can anyone
assist or point me in the right direction?

Here is the code to add the parent folder:

using (SPSite site = new SPSite(string.Concat(rootSitePath, "/",
webSitePath)))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists[listGuid];
SPListItemCollection listItems = list.Items;

foreach (MenuItem menuItem in menu.Items)
{
SPListItem listItem = list.Folders.Add();
listItem["MenuItemDisplayText"] =
menuItem.displayName;
listItem["MenuItemUrl"] = menuItem.url;
listItem["MenuItemHint"] = menuItem.hint;

listItem.Update();

//add a child to the above list item
}
}
}

0 new messages