以编程方式添加到 sharepoint 2010 列表

发布于 2024-12-08 19:50:21 字数 2695 浏览 2 评论 0原文

我正在尝试在共享点列表中创建一个新项目。没有收到任何错误消息,但该项目没有出现在列表中。

这是我的代码:

 '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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一身仙ぐ女味 2024-12-15 19:50:21

首先,尝试添加:

  <Field Name='ID'>New</Field>

另外,我建议删除除标题之外的其他字段。然后在成功后开始将它们添加回来。有两个原因:

  1. 您希望确保字段名称是正确的
  2. 非值类型,例如用户或查找(例如所有这些 Phil)可能需要在 ID;#Name 中进行格式化风格而不是简单的文字。

First, try adding:

  <Field Name='ID'>New</Field>

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:

  1. you want to make sure that your field names are correct
  2. non-value types like users or lookups (all those Phils, for example) might need to be formatted in the ID;#Name style rather than simple text.
凉风有信 2024-12-15 19:50:21

使用 C# 以编程方式创建 SharePoint 列表。

为我们新创建的列表添加查找字段。

这是示例代码。

public void createList()
{
     // choose your site
   SPSite site = new SPSite("http://merdev-moss:5050");
   SPWeb web = site.OpenWeb();
   SPListCollection lists = web.Lists;
     // create new Generic list called "My List"
   lists.Add("My List", "My list Description", SPListTemplateType.GenericList); 
   SPList newList = web.Lists["My List"];

 }

或尝试使用此链接
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.

public void createList()
{
     // choose your site
   SPSite site = new SPSite("http://merdev-moss:5050");
   SPWeb web = site.OpenWeb();
   SPListCollection lists = web.Lists;
     // create new Generic list called "My List"
   lists.Add("My List", "My list Description", SPListTemplateType.GenericList); 
   SPList newList = web.Lists["My List"];

 }

or try to use this link
http://devendra-sharepoint.blogspot.com/2012/01/creating-list-programatically-in_30.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文