RTF to TEXT

P

Peter Hale

Hi all

I'm doing a conversion and I need to convert an RTF field to TXT .

ie the input field ( read from a SQL table ) using a DataReader is in RTF
fomat - the output to another system needs to be in Text format - is
there an easy way to remove the formatting and only leave the text

Thanks

Pete
 
M

Michael Nemtsev

Hello Peter,

Smth like this http://www.codeproject.com/cs/library/nrtftree.asp, google
to find more samples

BTW, you can apply XSLT to transform from RTF to TXT format

PH> Hi all
PH>
PH> I'm doing a conversion and I need to convert an RTF field to TXT .
PH>
PH> ie the input field ( read from a SQL table ) using a DataReader is
PH> in RTF fomat - the output to another system needs to be in Text
PH> format - is there an easy way to remove the formatting and only
PH> leave the text
PH>
PH> Thanks
PH>
PH> Pete
PH>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
 
P

Peter Hale

Hi Michael

thank you for your reply - I had found that page but I really needed to go
to text so I kept looking and found I could use a RichText control on the
form ( hidden if necessary ) and then used the following code

System.Windows.Forms.RichTextBox rtfBox; // generated by the rtf control

// can also just create an "instance" of an RTF as well


string snotes = "";
rtfBox.Rtf = myDR["NOTETEXT"].ToString();
snotes = rtfBox.Text.ToString().Trim();
Console.WriteLine("convert - {0}",snotes); // to have a look

or

if you might havre some non rtf data - eg just text - in the field

try
{
rtfBox.Rtf = myDR["NOTETEXT"].ToString();
snotes = rtfBox.Text.ToString().Trim();
}
catch
{
snotes = myDR["NOTETEXT"].ToString().Trim();
}

I've just tried to find the MS documentation page where I found this but
like everything else - a needle in a haystack - I have favourited it at
the office so will post it later

Peter
 
P

Peter Hale

here is the link I was referring to

http://msdn2.microsoft.com/en-us/library/system.windows.forms.richtextbox.rtf.aspx

Peter



Peter Hale said:
Hi Michael

thank you for your reply - I had found that page but I really needed to go
to text so I kept looking and found I could use a RichText control on the
form ( hidden if necessary ) and then used the following code

System.Windows.Forms.RichTextBox rtfBox; // generated by the rtf
control

// can also just create an "instance" of an RTF as well


string snotes = "";
rtfBox.Rtf = myDR["NOTETEXT"].ToString();
snotes = rtfBox.Text.ToString().Trim();
Console.WriteLine("convert - {0}",snotes); // to have a look

or

if you might havre some non rtf data - eg just text - in the field

try
{
rtfBox.Rtf = myDR["NOTETEXT"].ToString();
snotes = rtfBox.Text.ToString().Trim();
}
catch
{
snotes = myDR["NOTETEXT"].ToString().Trim();
}

I've just tried to find the MS documentation page where I found this but
like everything else - a needle in a haystack - I have favourited it at
the office so will post it later

Peter



Michael Nemtsev said:
Hello Peter,

Smth like this http://www.codeproject.com/cs/library/nrtftree.asp, google
to find more samples

BTW, you can apply XSLT to transform from RTF to TXT format

PH> Hi all
PH> PH> I'm doing a conversion and I need to convert an RTF field to TXT
.
PH> PH> ie the input field ( read from a SQL table ) using a DataReader
is
PH> in RTF fomat - the output to another system needs to be in Text
PH> format - is there an easy way to remove the formatting and only
PH> leave the text
PH> PH> Thanks
PH> PH> Pete
PH> ---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do
not cease to be insipid." (c) Friedrich Nietzsche
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top