问题描述
我真的在寻找一个小的代码片段,或者一个关于这个主题的好教程.
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.htmlhttp://asadewa.wordpress.com/2007/11/19/adding-a-custom-content-type-specific-item-on-a-sharepoint-list/
简短介绍:
- 获取要向其中添加项目的列表的实例.
向列表中添加一个新项目:
- Get a instance of the list you want to add the item to.
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:如何以编程方式将项目添加到自定义列表实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!