C# 如何更新列表项?

C# 如何更新列表项?,c#,sharepoint,C#,Sharepoint,我一直在尝试使用c#以编程方式更新sharepoint网站上的列表项。 我成功地完成了WebServerReference。但是,我不明白以下项目是什么: 列表ID、视图ID、字段名ID等 在下面的代码中,我从 我应该用这些ListId、viewId、FieldName ID值替换我的值。我没有可以得到这些价值的数据。我一直在仔细检查我的sharepoint网站,但在任何地方都找不到这些价值观 /*Get Name attribute values (GUIDs) for list and vi

我一直在尝试使用c#以编程方式更新sharepoint网站上的列表项。 我成功地完成了
WebServerReference
。但是,我不明白以下项目是什么:

列表ID、视图ID、字段名ID

在下面的代码中,我从 我应该用这些
ListId、viewId、FieldName ID
值替换我的值。我没有可以得到这些价值的数据。我一直在仔细检查我的sharepoint网站,但在任何地方都找不到这些价值观

/*Get Name attribute values (GUIDs) for list and view. */
System.Xml.XmlNode ndListView = listService.GetListAndView("MyList", "");
string strListID = ndListView.ChildNodes[0].Attributes["Name"].Value;
string strViewID = ndListView.ChildNodes[1].Attributes["Name"].Value;

/*Create an XmlDocument object and construct a Batch element and its
attributes. Note that an empty ViewName parameter causes the method to use the default view. */
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
System.Xml.XmlElement batchElement = doc.CreateElement("Batch");
batchElement.SetAttribute("OnError", "Continue");
batchElement.SetAttribute("ListVersion", "1");
batchElement.SetAttribute("ViewName", strViewID);

/*Specify methods for the batch post using CAML. To update or delete, 
specify the ID of the item, and to update or add, specify 
the value to place in the specified column.*/
batchElement.InnerXml = "<Method ID='1' Cmd='Update'>" +
   "<Field Name='ID'>6</Field>" +
   "<Field Name='Title'>Modified sixth item</Field></Method>" +
   "<Method ID='2' Cmd='Update'><Field Name='ID'>7</Field>" +
   "<Field Name='Title'>Modified seventh item</Field></Method>" +
   "<Method ID='3' Cmd='Delete'><Field Name='ID'>5</Field>" +
   "</Method><Method ID='4' Cmd='New'>" +
   "<Field Name='Title'>Added item</Field></Method>";
/*获取列表和视图的名称属性值(GUID)*/
System.Xml.XmlNode ndListView=listService.GetListAndView(“MyList”,即“”);
字符串strListID=ndListView.ChildNodes[0]。属性[“名称”]。值;
字符串strViewID=ndListView.ChildNodes[1]。属性[“名称”]。值;
/*创建一个XmlDocument对象并构造一个批处理元素及其
属性。请注意,空ViewName参数会导致该方法使用默认视图*/
System.Xml.XmlDocument doc=new System.Xml.XmlDocument();
System.Xml.xmlement batchElement=doc.CreateElement(“批次”);
SetAttribute(“OnError”、“Continue”);
batchElement.SetAttribute(“ListVersion”、“1”);
SetAttribute(“视图名”,strViewID);
/*使用CAML指定批处理post的方法。要更新或删除,
指定项目的ID,要更新或添加,请指定
要放置在指定列中的值*/
batchElement.InnerXml=“”+
"6" +
“修改后的第六项”+
"7" +
“修改后的第七项”+
"5" +
"" +
“新增项目”;

尝试浏览列表设置页面,从URL获取列表ID;尝试浏览修改视图页面,从URL获取视图ID;尝试浏览列表设置页面,然后单击字段,从URL获取字段名称。或者,您也可以尝试类似Codeplex上的SharePoint Manager之类的方法来轻松查找此信息。

如果不想使用GUID,可以使用列表的显示名称作为列表ID