Tuesday 4 September 2012

How to insert hyperlink control in repeater table in repeater section in infopath 2010

Following code is using infopath 2010 code behind.


 




            XPathNavigator attachmentNav = MainDataSource.CreateNavigator();
            XPathNodeIterator rows1 = attachmentNav.Select("/my:myFields/my:group8/my:group9/my:group10", NamespaceManager);
            if (rows1.Count != 1)
            {
                string attachedFile = attachmentNav.SelectSingleNode("/my:myFields/my:group8/my:group9[" + Convert.ToString(rows1.Count) + "]/my:attachment", NamespaceManager).Value;
                if (attachedFile != string.Empty)
                {
                    attachmentNav = attachmentNav.SelectSingleNode("/my:myFields/my:group8/my:group9[" + Convert.ToString(rows1.Count) + "]/my:attachment", NamespaceManager);
                    // Convert the base64 encoded string into a byte array
                    InfoPathAttachmentDecoder decoder = new InfoPathAttachmentDecoder(attachedFile);
                    byte[] attachment = decoder.DecodedAttachment;
                    string fileName = decoder.Filename;
                    XmlDocument doc = new XmlDocument();
                    XmlNode group = doc.CreateElement("group11", NamespaceManager.LookupNamespace("my"));
                    XmlNode field = doc.CreateElement("url", NamespaceManager.LookupNamespace("my"));
                    XmlNode node = group.AppendChild(field);
                    node.InnerXml = fileName;
                    doc.AppendChild(group);
                    MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:group8/my:group9[" + Convert.ToString(rows1.Count) + "]/my:group10", NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator());
                    attachmentNav.SelectSingleNode("/my:myFields/my:group8/my:group9[" + Convert.ToString(rows1.Count) + "]/my:attachment", NamespaceManager).SetValue("");
                }
            }
            else
            {
                string attachedFile = attachmentNav.SelectSingleNode("/my:myFields/my:group8/my:group9/my:attachment", NamespaceManager).Value;
                if (attachedFile != string.Empty)
                {
                    attachmentNav = attachmentNav.SelectSingleNode("/my:myFields/my:group8/my:group9/my:attachment", NamespaceManager);
                    // Convert the base64 encoded string into a byte array
                    InfoPathAttachmentDecoder decoder = new InfoPathAttachmentDecoder(attachedFile);
                    byte[] attachment = decoder.DecodedAttachment;
                    string fileName = decoder.Filename;

                    XmlDocument doc = new XmlDocument();
                    XmlNode group = doc.CreateElement("group11", NamespaceManager.LookupNamespace("my"));
                    XmlNode field = doc.CreateElement("url", NamespaceManager.LookupNamespace("my"));
                    XmlNode node = group.AppendChild(field);
                    node.InnerXml = fileName;
                    doc.AppendChild(group);
                    MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:group8/my:group9/my:group10", NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator());
                    attachmentNav.SelectSingleNode("/my:myFields/my:group8/my:group9/my:attachment", NamespaceManager).SetValue("");
                }
            }

No comments:

Post a Comment