在这个精彩论坛中专家的真诚帮助下,我已经能够解析 SharePoint 列表返回的 xml,从而将所需的列表项放入 C# 列表中。
XDocument xdoc = XDocument.Parse(activeItemData.InnerXml);
XNamespace z = "#RowsetSchema";
List<int> listID = (from row in xdoc.Descendants(z + "row")
select (int)row.Attribute("ows_ID")).ToList();
List<string> listTitle = (from row in xdoc.Descendants(z + "row")
select (string)row.Attribute("ows_LinkTitle")).ToList();
我创建了一个 SQL 表,我想使用 Lists listID 和 listTitle 作为参数在我的表中插入值
System.Data.SqlClient.SqlConnection sqlConnection1 =
new System.Data.SqlClient.SqlConnection(MyconnectionString);
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "INSERT TechOpsProjectTracker (ID, [Project Name]) VALUES (@ID, @ProjectName)";
//What I want to do:
//1. @ID should get the values from the List listID: List<int> listID = (from row in xdoc.Descendants(z + "row") select (int)row.Attribute("ows_ID")).ToList();
//2. @ProjectName should get the values from the List listTitle: List<string> listTitle = (from row in xdoc.Descendants(z + "row") select (string)row.Attribute("ows_LinkTitle")).ToList();
//3. so each new record inserted in the table has ID and its corresponding Project Name. Something like this
/* ID Project Name
360 GEI Survey data to Sharepoint
378 Create back end and environment to support User demographic reporting
*/
可能还有其他一些可能更简单的方法来完成我的工作。请告诉我。TIA。