2011-10-07 113 views
0

我正在嘗試在SharePoint列表中創建一個新項目。沒有收到任何錯誤消息,但該項目沒有出現在列表中。以編程方式添加到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 

任何人都可以指出我要去的地方錯了

乾杯, 菲爾。

回答

0

首先,試着加入:

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

另外,我建議取消等領域,除了標題。然後開始添加它們,因爲你有成功。原因有二:

    你要確保你的字段名稱是正確的
  1. 非數值類型,如用戶或查找
  2. (所有這些菲爾斯,例如)可能需要在ID;#Name風格被格式化而不是簡單的文字。
0

以編程方式在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

相關問題