以网页形式打开InfoPath表单时展示图片

问题:当Infopath表单选择以浏览器形式打开时,图片功能控件是不兼容的,此时要在InfoPath中展示图片必须采用其他方式

 

解决方案:

    创建一个重复表,结构为:Pictures

                                           Picture

                                                title

                                                image

添加数据连接,获取图片,图片保存在SharePoint图片库中,链接为CumListConn,SharePoint中List为CumList

在InfoPath表单Loading事件中添加下面代码:

 

 XPathNodeIterator iter = this.DataSources["CumListConn"].CreateNavigator().Select("/dfs:myFields/dfs:dataFields/dfs:CumList", NamespaceManager);
            foreach (XPathNavigator pic in iter)
            {
               // XPathNavigator pic = iter.Current;
                string title = pic.SelectSingleNode("@Title", NamespaceManager).Value;
               
                string url = "http://<server_name>/MyPictures/" + title + ".jpg";
                addImageToTable(title, url);
            }
          

            // Remove the first empty row from the repeating table
            XPathNavigator mainDSNav = MainDataSource.CreateNavigator();
            if (String.IsNullOrEmpty(mainDSNav.SelectSingleNode( "/my:myFields/my:pictures/my:picture[1]/my:title", NamespaceManager).Value)
                && String.IsNullOrEmpty(mainDSNav.SelectSingleNode("/my:myFields/my:pictures/my:picture[1]/my:image", NamespaceManager).Value))
            {
                XPathNavigator nav = mainDSNav.SelectSingleNode(
                "/my:myFields/my:pictures/my:picture[1]", NamespaceManager);
                nav.DeleteSelf();

            }

 

addImageToTable方法代码:

 

 public void addImageToTable(string title, string url)
        {
            // Create a row for the picture
            XmlDocument doc = new XmlDocument();
            XmlNode group = doc.CreateElement("picture", NamespaceManager.LookupNamespace("my"));
            XmlNode field = doc.CreateElement("title", NamespaceManager.LookupNamespace("my"));
            XmlNode node = group.AppendChild(field);
            node.InnerText = title;
            field = doc.CreateElement("image", NamespaceManager.LookupNamespace("my"));
            node = group.AppendChild(field);
            node.InnerXml = "<img xmlns=/"http://www.w3.org/1999/xhtml/" src=/"" + url + "/"/>";
            field = doc.CreateElement("notes", NamespaceManager.LookupNamespace("my"));
           

            doc.AppendChild(group);

            // Add the picture to the repeating table
            XPathNavigator mainDSNav = MainDataSource.CreateNavigator();
            mainDSNav.SelectSingleNode("/my:myFields/my:pictures", NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator());
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值