c# - 共享点 : How can I programmatically add items to a custom list instance

标签 c# sharepoint content-type

我真的在寻找一个小代码片段,或者关于这个主题的一个很好的教程。

我有一个 C# 控制台应用程序,我将使用它以某种方式将列表项添加到我的自定义列表中。我也创建了自定义内容类型。所以不确定我是否也需要从这种内容类型创建一个 C# 类。也许不是。

提前致谢

最佳答案

我认为这两篇博文应该可以帮助您解决问题。

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/

简短介绍:

  1. 获取要将项目添加到的列表的实例。
  2. 向列表中添加一个新项目:

    SPListItem newItem = list.AddItem();
    
  3. 要将新项目绑定(bind)到内容类型,您必须为新项目设置内容类型 ID:

    newItem["ContentTypeId"] = <Id of the content type>;
    
  4. 设置在您的内容类型中指定的字段。

  5. 提交您的更改:

    newItem.Update();
    

关于c# - 共享点 : How can I programmatically add items to a custom list instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1333492/

相关文章:

c# - 具有派生参数的派生类和覆盖方法 : how to code it better?

c# - 如何将 FluentValidation 集成到 MVC4 中

sharepoint - 如何以编程方式将目标列表添加到 Sharepoint 中的新增功能 Web 部件(或如何处理未记录的命名空间)

java - 如何使用固定输入创建 GraphServiceClient 的 IAuthenticationProvider 对象

tomcat - Grails - 将 HTML 文件作为 UTF-8 提供?

c# - foreach block 缺少结束字符 "}"

c# - ICSharpCode.SharpZipLib.Zip crc32

iphone - 使用 initWithContentsOfUrl 时如何设置内容类型

http-headers - 如何为不同的浏览器设置正确的 Content-Type header ?

c# - 项目控制 : Change Property Of Control in ItemControl Based On "Content" of Control