SharePoint : How can I programmatically add items to a custom list instance

后端 未结 5 1339
独厮守ぢ
独厮守ぢ 2021-02-01 17:22

I am really looking for either a small code snippet, or a good tutorial on the subject.

I have a C# console app that I will use to somehow add list items to my custom l

5条回答
  •  独厮守ぢ
    2021-02-01 18:05

    I think these both blog post should help you solving your problem.

    http://blog.the-dargans.co.uk/2007/04/programmatically-adding-items-to.html http://asadewa.wordpress.com/2007/11/19/adding-a-custom-content-type-specific-item-on-a-sharepoint-list/

    Short walk through:

    1. Get a instance of the list you want to add the item to.
    2. Add a new item to the list:

      SPListItem newItem = list.AddItem();
      
    3. To bind you new item to a content type you have to set the content type id for the new item:

      newItem["ContentTypeId"] = ;
      
    4. Set the fields specified within your content type.

    5. Commit your changes:

      newItem.Update();
      

提交回复
热议问题