Convert RTF to Text Using Same Library as SPS
-
- Posts: 27
- Joined: Tue Jun 28, 2016 2:26 pm
Convert RTF to Text Using Same Library as SPS
If I get the text from Order.Title.Commitments.Requirements.Text, it is a string in RTF format. How can I convert this string to plain text using the same library or methods SPS uses?
-
- Posts: 1377
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: Convert RTF to Text Using Same Library as SPS
Our RTF to text methods are not public. We decode the mangled RTF string directly since on server packages, RichTextBox controls are not available to perform this function.
Bob Richards, Senior Software Developer, SoftPro
-
- Posts: 27
- Joined: Tue Jun 28, 2016 2:26 pm
Re: Convert RTF to Text Using Same Library as SPS
Thanks Bob, I didn't realize I could do this with a built-in control. WinForms is in the GAC, so I'm able to use the RichTextBox from IronPython to achieve good results. Here is a working example.
Code: Select all
import clr
clr.AddReference('System.Windows.Forms')
from System.Windows.Forms import RichTextBox
rtb = RichTextBox()
rtb.Rtf = Context.Title.Commitments[0].Requirements[0].Text
Context.RelatedOrders = rtb.Text
-
- Posts: 1377
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: Convert RTF to Text Using Same Library as SPS
Yep. That's what I would do. Be careful that you don't create lots of instances of the control since that has the potential to drastically slow things down. You certainly would not want to do this in a Custom Order Rule.
Bob Richards, Senior Software Developer, SoftPro