Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / April 2007

Tip: Looking for answers? Try searching our database.

Transfer text from Rich Text Box

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew - 07 Mar 2006 23:52 GMT
Does anyone know of a way to transfer text from one rich text box to another
and being able to keep the return lines in there.

Thanks,
 Andrew
Adam Harding - 08 Mar 2006 11:29 GMT
Hi

You can transfer the text but the carriage returns will not pass accross.

just set the second RTB's default value to the first job done.

Cheers Adam

> Does anyone know of a way to transfer text from one rich text box to another
> and being able to keep the return lines in there.
>
> Thanks,
>   Andrew
S.Y.M. Wong-A-Ton - 08 Mar 2006 13:00 GMT
The contents of a rich text box is stored as XHTML. To preserve line breaks,
which are essentially achieved through the use of <DIV> elements within the
contents of the rich text box, you would have to copy the entire XML content
of the node pertaining to the first rich text box, create a new node, set the
XML content of the newly created node to the content copied from the first
rich text box, and then replace the node pertaining to the second rich text
box with the new node using replaceChild().
---
S.Y.M. Wong-A-Ton

> Does anyone know of a way to transfer text from one rich text box to another
> and being able to keep the return lines in there.
>
> Thanks,
>   Andrew
Andrew - 08 Mar 2006 15:54 GMT
It seems that InfoPath will not allow me to do this in code.  I think I might
have to write a webservice to transfer the text.

> The contents of a rich text box is stored as XHTML. To preserve line breaks,
> which are essentially achieved through the use of <DIV> elements within the
[quoted text clipped - 11 lines]
> > Thanks,
> >   Andrew
S.Y.M. Wong-A-Ton - 08 Mar 2006 17:19 GMT
If your scenario includes simply copying text from one RTF to another on one
InfoPath form, then this is doable through code without using a web service.
I don't understand why you would need a web service. Is there a database
(that you haven't mentioned) somewhere in the equation?
---
S.Y.M. Wong-A-Ton

> It seems that InfoPath will not allow me to do this in code.  I think I might
> have to write a webservice to transfer the text.
[quoted text clipped - 14 lines]
> > > Thanks,
> > >   Andrew
Andrew - 08 Mar 2006 19:02 GMT
Nope no database.  I have code behind in c#.  I created a test form that just
has a Rich TextBox a and b.   And when the user submits the form I would like
to transfer the Rich Text from A to B and beable to keep the line breaks.

I've tried to do something like this  
Node =  
thisXDocument.DOM.selectSingleNode("/my:myFields/my:a").cloneNode(False)
thisXDocument.DOM.selectSingleNode("/my:myFields/my:b").appendChild(Node)

I do understand why that won't work but I'm still new to XML.

and If I do this ...
thisXDocument.DOM.selectSingleNode("/my:myFields/my:b").text =
thisXDocument.DOM.selectSingleNode("/my:myFields/my:a").text

Then it copies the text over without keeping the line breaks.

Thanks for any help!
- Andrew

> If your scenario includes simply copying text from one RTF to another on one
> InfoPath form, then this is doable through code without using a web service.
[quoted text clipped - 21 lines]
> > > > Thanks,
> > > >   Andrew
S.Y.M. Wong-A-Ton - 09 Mar 2006 09:03 GMT
If your RTF-a contains line breaks and you put a breakpoint on e.g.

string RTF-a = thisXDocument.DOM.selectSingleNode("/my:myFields/my:a").xml;

you will see a bunch of <DIV> elements contained in <my:a>. What worked for
me was to build a loop over the childNodes contained in <my:a> and then
compose a string from these childNodes. I haven't yet found a "nicer" way to
copy the XML inside a node. You can do a check on

thisXDocument.DOM.selectSingleNode("/my:myFields/my:a").hasChildNodes()

before starting the loop over the childNodes. Then you must retrieve the
nodeName, nodeType, and namespaceURI of <my:b> (these are all properties of a
node) and use them to create the new XML for this node as a string that
contains the inner XML copied from <my:a>.

You can then use thisXDocument.CreateDOM() to instantiate a new XML node
(we'll call this newChild), and then newChild.loadXML() to load the XML
string for the new <my:b> into this new XML node.

Then you retrieve the old <my:b> (let's call it oldChild) and with a
replaceChild(), you replace it with the new XML node for <my:b> like this

oldChild.parentNode.replaceChild(newChild.documentElement, oldChild);

Hope this helps. If you're still having difficulty getting this to work,
I'll convert your scenario to a "recipe" (=solution) and post it on my
website this weekend.
---
S.Y.M. Wong-A-Ton

> Nope no database.  I have code behind in c#.  I created a test form that just
> has a Rich TextBox a and b.   And when the user submits the form I would like
[quoted text clipped - 41 lines]
> > > > > Thanks,
> > > > >   Andrew
Andrew - 09 Mar 2006 14:15 GMT
Thank you for all of your help!!  I got it working this morning.  The only
difference I had to make was I also needed to keep everything that is in the
OldChile.  So that the new text would be first then the old test second.  

Oh you mentioned that you have a website, may I have the web address to
check it out?  

Thank you again!!

- Andrew

> If your RTF-a contains line breaks and you put a breakpoint on e.g.
>
[quoted text clipped - 72 lines]
> > > > > > Thanks,
> > > > > >   Andrew
S.Y.M. Wong-A-Ton - 09 Mar 2006 14:56 GMT
Glad to hear that you got it to work! And since you did, I won't be posting
the solution on my website. But you're free to check out the website at
http://enterprise-solutions.swits.net
---
S.Y.M. Wong-A-Ton

> Thank you for all of your help!!  I got it working this morning.  The only
> difference I had to make was I also needed to keep everything that is in the
[quoted text clipped - 83 lines]
> > > > > > > Thanks,
> > > > > > >   Andrew
Gustavo Hernandez - 16 Apr 2007 22:44 GMT
Hi My name is Gustavo from Monterrey mexico

I have the same problem, but i have one Rich Text field with tables, text in
bold, text in different size, etc...and i would like to copy the values from
one field to another field,
do you think this code could be used also to pass that kind of information?

> If your RTF-a contains line breaks and you put a breakpoint on e.g.
>
[quoted text clipped - 72 lines]
> > > > > > Thanks,
> > > > > >   Andrew
S.Y.M. Wong-A-Ton - 17 Apr 2007 07:24 GMT
If the other field is a richt text field, then yes, the same principles
should apply. If you're using InfoPath 2007, you might even get away with
using the InnerXml property to transfer the entire contents in one step; I
haven't tried it out, though. I would say: Just give it a go and see if it
works.
---
S.Y.M. Wong-A-Ton

> Hi My name is Gustavo from Monterrey mexico
>
[quoted text clipped - 79 lines]
> > > > > > > Thanks,
> > > > > > >   Andrew
Gustavo Hernandez - 17 Apr 2007 13:56 GMT
Thanks for your quick answer.

And yes both fields are rich text.  I'm trying to use your suggestion about
how to transfer text from one field to another, but i'm having problems when
i want to do the replace child instruction.  My field "B" does not have any
child node....so,
How can i create a new child for my field "B" where i want to pass the rich
text value from my field "A" ?, i mean i can do a loop for my field "A" and
get the XML data, but i don't understand how to pass every XML data for each
child of my field "A" to my field "B".

> If the other field is a richt text field, then yes, the same principles
> should apply. If you're using InfoPath 2007, you might even get away with
[quoted text clipped - 87 lines]
> > > > > > > > Thanks,
> > > > > > > >   Andrew
S.Y.M. Wong-A-Ton - 18 Apr 2007 02:04 GMT
You can do it on a number of ways. Which version of InfoPath are you using?
---
S.Y.M. Wong-A-Ton

> Thanks for your quick answer.
>
[quoted text clipped - 98 lines]
> > > > > > > > > Thanks,
> > > > > > > > >   Andrew
Gustavo Hernandez - 23 Apr 2007 17:26 GMT
I'm using InfoPath 2003.  Finally i found a way to do it.  A little different
than your suggestions, but following your instructions.  One thing different
that i did was copy the xml of my field A into a string variable and only
replace the name of the child for the field2 and then do a replace child from
parent node of both fields.

               IXMLDOMNode node1 =
doc.DOM.documentElement.selectSingleNode("./my:parentnode/my:Field1");
           
               if (node1 != null)
               {
                 
                   IXMLDOMDocument newchild = doc.CreateDOM();
                   childtext = node1.xml.ToString();
                   string newtxtofnode2= childtext.Replace("NameOfChild_1",
"NameOfChild_2");
                   newchild.loadXML(newtxtofnode2);

                   oldchild =
doc.DOM.documentElement.selectSingleNode("./my:ParentNode/my:Field2");
                   
oldchild.parentNode.replaceChild(newchild.documentElement, oldchild);
               }

And it works !!

Thanks for your help !

> You can do it on a number of ways. Which version of InfoPath are you using?
> ---
[quoted text clipped - 102 lines]
> > > > > > > > > > Thanks,
> > > > > > > > > >   Andrew
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.