Formatting Rich Text in Rich Text Field RRS feed

  • Question

  • Hello.

    On an InfoPath Browser Form I am using a Data Connection to look up to a list in SharePoint.  The list contains a field in Rich Text Format.  A button on my form allows me to query the list and pull the Rich Text Field into a List Box on the form.  The user can then select an item from this list and add it to a Rich Text box on the form.

    The problem is that when it transfers the field into the List Box it is wrapped in a <div> tag and also other HTML tags appear e.g. &nbsp;.

    I want it to keep the rich text formatting between the field on the list in SharePoint and the control on the InfoPath Form.

    How do I keep the formatting?
    Wednesday, May 6, 2009 2:59 PM

All replies

  • Additionally here is my code for adding the item from the list box to the rich text field in infopath: public void btnAddItem_Clicked(object sender, ClickedEventArgs e) { // Write your code here. //GET A REFERENCE TO THE LISTBOX NODE XPathNavigator myRoot = MainDataSource.CreateNavigator(); XPathNavigator nodeList = null; nodeList = myRoot.SelectSingleNode("/my:thing/my:filtering/my:listboxitem", this.NamespaceManager); string sListItem = nodeList.Value.ToString(); string bCompliant = "true"; //SET UP THE NAMESPACE string myNamespace = NamespaceManager.LookupNamespace("my"); //ADD NODE TO TO THE REPEATING TABLE using (XmlWriter writer = MainDataSource.CreateNavigator().SelectSingleNode("/my:thing/my:items", NamespaceManager).AppendChild()) { writer.WriteStartElement("item", myNamespace); //ADD SELECTED QUESTION TO THE NEW REPEATING NODE writer.WriteElementString("itemtitle", myNamespace, sListItem); writer.WriteElementString("isCompliant", myNamespace, bCompliant); writer.WriteEndElement(); writer.Close(); } }
    Wednesday, May 6, 2009 4:33 PM
  • I have tried replacing <div> with <div xmlns="" but it is still just rendered as a string in the "Rich" Text control.

    Any one got ideas on this? 
    Thursday, May 7, 2009 1:52 PM
  • you have to set the value updating the innerxml property of the field.

    example: (replace your xpath)
    string  url = "";
    mainDSNav.SelectSingleNode("/my:misCampos/my:pictures/my:picture/my:imagen", NamespaceManager).InnerXml = "<img xmlns=\"\" src=\"" + url + "\"/>";

    If you use it, mark it as useful.
    Thursday, May 28, 2009 10:31 PM
  • Thanks for replying Carlos.

    I could not find a .InnerXML method on the WRITER object to do it in the way you're saying.  I'm using the writer object so that I can use the .AppendChild because my Rich Text field lives inside a Repeating node on the form.
    Friday, May 29, 2009 8:31 AM
  • Even if it is a repeating node, you can get it by using the selectsinglenode, if you are interacting with the table and the user click a button you get referenced to the correct node, if not you need to select your nodes or using an xpath expression like "/my:misCampos/my:pictures/my:picture/my:imagen[@ID=1]" the [ ] is like a where condition.
    it is much simpler in that way. after you insert the child element in the table.

    item = MainDataSource.CreateNavigator().SelectSingleNode("/my:thing/my:items/my:item[last()]", NamespaceManager)
    item.selectsinglenode("my:itemtitle",tnis.namespacemanager).InnerXML = value

    hope that helps

    If you use it, don't loose it.
    Friday, May 29, 2009 8:52 PM