Page 1 of 1

Convert RTF to Text Using Same Library as SPS

Posted: Sat Jul 21, 2018 2:05 pm
by kkirkfield
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?

Re: Convert RTF to Text Using Same Library as SPS

Posted: Mon Jul 23, 2018 10:37 am
by BobRichards
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.

Re: Convert RTF to Text Using Same Library as SPS

Posted: Mon Jul 23, 2018 1:22 pm
by kkirkfield
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

Re: Convert RTF to Text Using Same Library as SPS

Posted: Mon Jul 23, 2018 2:24 pm
by BobRichards
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.