Geeks With Blogs
Dennis Bottjer | MVP

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);
Posted on Friday, October 3, 2008 5:15 AM SharePoint | Back to top


Comments on this post: Manipulating SharePoint Lists with Code

# re: Manipulating SharePoint Lists with Code
Requesting Gravatar...
I love how clear and simple the example code and explanation are for such an important task to achieve.
Left by Tom Resing on Nov 07, 2008 4:17 PM

Your comment:
 (will show your gravatar)


Copyright © DennisBottjer | Powered by: GeeksWithBlogs.net