将数据从Sharepoint连接复制到本地重复表

时间:2018-11-09 09:30:46

标签: c# sharepoint infopath

我希望将数据从共享点连接复制到本地重复表,以便我可以修改和重新提交数据。

我一直在看下面的文章,该文章似乎描述了我的要求: http://www.bizsupportonline.net/infopath2007/copy-rows-from-sharepoint-list-to-main-data-source.htm

我对C#不熟悉,因此我希望对代码有所帮助,因为上表应与预览中的下表匹配

预先感谢

Infopath form screenshot

Secondary connection screenshot

Preview of form after clicking button

链接到按钮的C#代码     私有无效AddItem(字符串标题,字符串ID)         {             XmlDocument doc =新的XmlDocument();             XmlNode组= doc.CreateElement(“ group2”,             NamespaceManager.LookupNamespace(“ my”));

        XmlNode field = doc.CreateElement("field1",
        NamespaceManager.LookupNamespace("my"));
        XmlNode node = group.AppendChild(field);
        node.InnerText = title;

        field = doc.CreateElement("field2",
        NamespaceManager.LookupNamespace("my"));
        node = group.AppendChild(field);
        node.InnerText = id;

        doc.AppendChild(group);

        MainDataSource.CreateNavigator().SelectSingleNode(
        "/my:myFields/my:group1",
        NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator());
    }

    private void DeleteFirstEmptyItem()
    {
        XPathNavigator domNav = MainDataSource.CreateNavigator();
        XPathNavigator itemNav = domNav.SelectSingleNode(
        "/my:myFields/my:group1/my:group2[1]",
        NamespaceManager);

        if (itemNav != null)
            itemNav.DeleteSelf();
    } 

    public void CTRL13_5_Clicked(object sender, ClickedEventArgs e)
    {
        XPathNavigator secDSNav = DataSources["TestCustomList"].CreateNavigator();

        // Retrieve the rows of the secondary data source
        XPathNodeIterator rows = secDSNav.Select(
        "/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW",
        NamespaceManager);

        // Loop through the rows of the secondary data source and fill the repeating table
        while (rows.MoveNext())
        {
            string title = rows.Current.SelectSingleNode(
            "/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:Title", NamespaceManager).Value;
            string id = rows.Current.SelectSingleNode(
            "/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:ID", NamespaceManager).Value;

            // Add the item to the repeating table
            AddItem(title, id );
        }

        // Remove the first empty item from the repeating table
        DeleteFirstEmptyItem();
    }

1 个答案:

答案 0 :(得分:0)

经过反复试验,看起来字符串变量title和id的声明不应引用完整的Xpath

while (rows.MoveNext())
{
    string title = rows.Current.SelectSingleNode(
    "d:Title", NamespaceManager).Value;
    string id = rows.Current.SelectSingleNode(
    "d:ID", NamespaceManager).Value;

     // Add the item to the repeating table
     AddItem(title, id);
}

Desired result