Dennis Bottjer | ASP.NET + SharePoint Architect, Trainer & Speaker

"An Ounce of Prevention is Worth a Pound of Cure" - Ben Franklin
posts - 168, comments - 59, trackbacks - 41

My Links

News

Add to Technorati Favorites The views expressed in this blog are mine and mine alone, not that of my employer, Microsoft, or anyone else’s. No warrantee is given for the quality of any material on this site.

Tag Cloud

Archives

Post Categories

Manipulating SharePoint Lists with Code

How do I create a custom list?

   1: Guid listId = webSite.Lists.Add("Sample", "Sample List", SPListTemplateType.GenericList);
   2:               
How to determine if a list already exists within an SPWeb?
   1: public static bool DoesListExist(SPWeb web, String listName)
   2:        {
   3:            foreach (SPList list in web.Lists)
   4:            {
   5:                if (true == list.Title.Equals(listName, StringComparison.OrdinalIgnoreCase))
   6:                    return true;
   7:            }
   8:            return false;
   9:        }

How to determine if a column (field) already exists?

   1: if (!list.Fields.ContainsField("Description"))
   2:                     list.Fields.Add("Description", SPFieldType.Note, false);

How to add a lookup column to a list?

   1: Guid listGuid = webSite.Lists["lookupList"].ID;
   2:                 Guid listId = webSite.Lists.Add("Sample", "Sample List", SPListTemplateType.GenericList);
   3:                 SPList list = webSite.Lists[listId] as SPList;
   4:                 list.Fields.AddLookup("Sample Lookup", listGuid, true);

Print | posted on Friday, October 3, 2008 5:15 AM | Filed Under [ SharePoint ]

Feedback

Gravatar

# re: Manipulating SharePoint Lists with Code

I love how clear and simple the example code and explanation are for such an important task to achieve.
11/7/2008 4:17 PM | Tom Resing
Gravatar

# Websites tagged "lists" on Postsaver

2/6/2009 3:13 AM | www.postsaver.org
Gravatar

# SharePoint Search Tips

4/29/2009 5:23 AM | drowningintechnicaldebt.com
Comments have been closed on this topic.

Powered by: