的SharePoint:如何编程方式将项目添加到自定义列表实例 [英] SharePoint : How can I programmatically add items to a custom list instance

查看:197
本文介绍了的SharePoint:如何编程方式将项目添加到自定义列表实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待为任何一个小的代码片段,或关于这个问题一个很好的教程。

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

我有我会用某种方式列表项添加到我的自定义列表一个C#控制台应用程序。我创建了一个自定义内容类型了。所以,不知道如果我需要创建此内容的C#类类型了。也许不是。

I have a C# console app that I will use to somehow add list items to my custom list. I have created a custom content type too. So not sure if I need to create an C# class from this content type too. Perhaps not.

在此先感谢

推荐答案

我觉得这两个博客文章应该帮你解决你的问题。

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 /添加-一个定制化内容类型特定项目上-A-的SharePoint列表/

短穿行:


  1. 获取您要添加的项目。

  2. 添加一个新的项目列表的一个实例到列表:

  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();


  • 要新的项目捆绑你到内容类型,你必须设置内容类型ID为新项目:

  • To bind you new item to a content type you have to set the content type id for the new item:

    newItem["ContentTypeId"] = <Id of the content type>;
    


  • 将您的内容类型中指定的字段。

  • Set the fields specified within your content type.

    提交更改:

    newItem.Update();
    


  • 这篇关于的SharePoint:如何编程方式将项目添加到自定义列表实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆