以编程方式添加到 sharepoint 2010 列表
我正在尝试在共享点列表中创建一个新项目。没有收到任何错误消息,但该项目没有出现在列表中。
这是我的代码:
'Declare and initialize Lists Web service.
Dim listService As New Lists()
'Authenticate
listService.Credentials = System.Net.CredentialCache.DefaultCredentials
'Set the Url property of the service for the path to a subsite.
listService.Url = "http://site/subsite/_vti_bin/lists.asmx"
'Get Name attribute values (GUIDs) for list and view.
Dim ndListView As System.Xml.XmlNode = listService.GetListAndView(listguid, "")
Dim strListID As String = ndListView.ChildNodes(0).Attributes("Name").Value
Dim strViewID As String = ndListView.ChildNodes(1).Attributes("Name").Value
'Create an XmlDocument object and construct a Batch element and its
'attributes. Empty string as view means use the default view.
Dim doc As New System.Xml.XmlDocument()
Dim batchElement As System.Xml.XmlElement = doc.CreateElement("Batch")
batchElement.SetAttribute("OnError", "Continue")
batchElement.SetAttribute("ListVersion", "1")
batchElement.SetAttribute("ViewName", strViewID)
'Specify methods for the batch post using CAML.
'Command id 1 = new
batchElement.InnerXml = "<Method ID='1' Cmd='New'>" +
"<Field Name='Title'>test</Field>" +
"<Field Name='AssignedTo'>Phil</Field>" +
"<Field Name='Status'>Active</Field>" +
"<Field Name='Priority'>Low</Field>" +
"<Field Name='Comment'>test</Field>" +
"<Field Name='Category'>test</Field>" +
"<Field Name='DueDate'>9/27/2011 12:00 AM</Field>" +
"<Field Name='RelatedIssues'></Field>" +
"<Field Name='V3Comments'>test</Field>" +
"<Field Name='NameAndSurname'>test test</Field>" +
"<Field Name='StudentNo'>209203003</Field>" +
"<Field Name='Account'>accounts</Field>" +
"<Field Name='Author'>Phil</Field>" +
"<Field Name='Complaints'>Complaints</Field>" +
"<Field Name='Edited'>Phil</Field></Method>"
Try
listService.UpdateListItems(strListID, batchElement)
LabelStatus.Text = "Call Escalated to sharepoint, ok."
Catch ex As Exception
LabelStatus.Text = ex.ToString
End Try
任何人都可以指出我哪里出错了
干杯, 菲尔.
I am trying to create a new item in a sharepoint list. Not getting any error messages but the item does not appear in the list.
Here is my code:
'Declare and initialize Lists Web service.
Dim listService As New Lists()
'Authenticate
listService.Credentials = System.Net.CredentialCache.DefaultCredentials
'Set the Url property of the service for the path to a subsite.
listService.Url = "http://site/subsite/_vti_bin/lists.asmx"
'Get Name attribute values (GUIDs) for list and view.
Dim ndListView As System.Xml.XmlNode = listService.GetListAndView(listguid, "")
Dim strListID As String = ndListView.ChildNodes(0).Attributes("Name").Value
Dim strViewID As String = ndListView.ChildNodes(1).Attributes("Name").Value
'Create an XmlDocument object and construct a Batch element and its
'attributes. Empty string as view means use the default view.
Dim doc As New System.Xml.XmlDocument()
Dim batchElement As System.Xml.XmlElement = doc.CreateElement("Batch")
batchElement.SetAttribute("OnError", "Continue")
batchElement.SetAttribute("ListVersion", "1")
batchElement.SetAttribute("ViewName", strViewID)
'Specify methods for the batch post using CAML.
'Command id 1 = new
batchElement.InnerXml = "<Method ID='1' Cmd='New'>" +
"<Field Name='Title'>test</Field>" +
"<Field Name='AssignedTo'>Phil</Field>" +
"<Field Name='Status'>Active</Field>" +
"<Field Name='Priority'>Low</Field>" +
"<Field Name='Comment'>test</Field>" +
"<Field Name='Category'>test</Field>" +
"<Field Name='DueDate'>9/27/2011 12:00 AM</Field>" +
"<Field Name='RelatedIssues'></Field>" +
"<Field Name='V3Comments'>test</Field>" +
"<Field Name='NameAndSurname'>test test</Field>" +
"<Field Name='StudentNo'>209203003</Field>" +
"<Field Name='Account'>accounts</Field>" +
"<Field Name='Author'>Phil</Field>" +
"<Field Name='Complaints'>Complaints</Field>" +
"<Field Name='Edited'>Phil</Field></Method>"
Try
listService.UpdateListItems(strListID, batchElement)
LabelStatus.Text = "Call Escalated to sharepoint, ok."
Catch ex As Exception
LabelStatus.Text = ex.ToString
End Try
Can anyone point out where I am going wrong
Cheers,
Phil.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,尝试添加:
另外,我建议删除除标题之外的其他字段。然后在成功后开始将它们添加回来。有两个原因:
ID;#Name
中进行格式化风格而不是简单的文字。First, try adding:
Also, I would suggest removing other fields, except for Title. And then start adding them back in as you have success. There are two reasons:
ID;#Name
style rather than simple text.使用 C# 以编程方式创建 SharePoint 列表。
为我们新创建的列表添加查找字段。
这是示例代码。
或尝试使用此链接
http://devendra-sharepoint.blogspot.com/2012 /01/creating-list-programatically-in_30.html
Create a SharePoint list programmatically in C#.
Add lookup field for our newly created list.
This is a sample code.
or try to use this link
http://devendra-sharepoint.blogspot.com/2012/01/creating-list-programatically-in_30.html