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

    技术2022-07-04  112

    问题:当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)