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

后端 未结 5 1335
独厮守ぢ
独厮守ぢ 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:00

    You can create an item in your custom SharePoint list doing something like this:

    using (SPSite site = new SPSite("http://sharepoint"))
    {
        using (SPWeb web = site.RootWeb)
        {
            SPList list = web.Lists["My List"];
            SPListItem listItem = list.AddItem();
            listItem["Title"] = "The Title";
            listItem["CustomColumn"] = "I am custom";
            listItem.Update();
         }
    }
    

    Using list.AddItem() should save the lists items being enumerated.

提交回复
热议问题