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

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

    To put it simple you will need to follow the step.

    1. You need to reference the Microsoft.SharePoint.dll to the application.
    2. Assuming the List Name is Test and it has only one Field "Title" here is the code.

              using (SPSite oSite=new SPSite("http://mysharepoint"))
          {
              using (SPWeb oWeb=oSite.RootWeb)
              {
                  SPList oList = oWeb.Lists["Test"];
                  SPListItem oSPListItem = oList.Items.Add();
                  oSPListItem["Title"] = "Hello SharePoint";
                  oSPListItem.Update();
              }
      
          }
      
    3. Note that you need to run this application in the Same server where the SharePoint is installed.

    4. You dont need to create a Custom Class for Custom Content Type

提交回复
热议问题