Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am new to SharePoint 2010, can you please help me to create a SharePoint list and basic CRUD operations?

share|improve this question
add comment

2 Answers

To create a list:

 Guid newListId = site.Lists.Add("My Custom List", "This list was created programmatically", site.ListTemplates["Custom List"]);
 //This is optional = just to get the list and put it on the left navigation.
 SPList newList = site.Lists[newListId];
 newList.OnQuickLaunch = true;
 newList.Update();

To create, update and delete list items:

 SPListItem itm = myList.Items.Add();
 itm["Title"] = "Test Item";
 itm["Data 1"] = "Flamingo";
 itm.Update();
 //*** Update the item
 itm["Data 1"] = "Dalmation";
 itm.Update();
 //*** Delete the item
 itm.Delete();

To get an item: SPListItem itm = myList.GetItemById( itemId );

You can also use SPQuery to get a list item or many items.

A long time ago I wrote about how to perform some of these basic tasks in some blog posts.

share|improve this answer
    
This answer definitely points out the basics. However, its worth pointing out that if a user does not has permissions to create list, create list item, edit list item, or delete list items, etc., SP will throw ugly errors. I learned this the hard way. Almost every object in SP has a .doesUserHasPermissions() method. You should definitely play around with that. It will help you write more robust code. –  Pathachiever11 Jul 24 '12 at 22:40
add comment

Very much depend on how you want to create that list.

  • As enduser through UI
  • As developer programmatically
  • As IT-Pro using powershell

If it's as an end-user the

  • Click Site Actions
  • click View All Site Content
  • click Create

For more options see Create or delete a list

share|improve this answer
add comment

Your Answer

 
discard

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.