• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1772
  • Last Modified:

C# Remove RTF formatting from a string

Hi.. I'm trying to remove all RTF formatting from a string (The source is Word Document - with all the 'garbage' Word adds).
But I get invalid file format.  Any ideas..

   string x = @"<html>  <head>   <style type='text/css'>    .c0 { margin-left:0pt;margin-top:0pt;margin-right:0pt;margin-bottom:7.5pt; }    .c1 { font-size:16pt; }    .c2 { font-size:7.5pt;text-decoration:underline; }    .c3 { font-family:'Times New Roman';font-size:48pt; }   </style>  </head>  <body>  <p class='c0'>Hellow</p>  <p class='c0'></p>  <p class='c0'>asdfdafdf</p>  <p class='c0'></p>  <p class='c0'><span class='c1'>fadsfdafdf</span></p>  <p class='c0'></p>  <p class='c0'></p>  <p class='c0'></p>  <p class='c0'></p>  <p class='c0'></p>  <p class='c0'></p>  <p class='c0'><span class='c2'>asdffasdf</span></p>  <p class='c0'></p>  <p class='c0'></p>  <p class='c0'></p>  <p class='c0'><span class='c3'>asdfafdasf</span></p>  </body>  </html>  ";
            System.Windows.Forms.RichTextBox rtfBox = new System.Windows.Forms.RichTextBox();
            rtfBox.Rtf = x.Trim();
            x = rtfBox.Text.ToString().Trim();
  • 2
1 Solution
what is your approach and what is not working?
JElsterAuthor Commented:
I use the System.Windows.Forms.RichTextBox to load the string and 'get' the string.
The enclose code does not work
It does not work that way.  Try loading the text into a normal text box. I am sure if that works either but you could try. Do you have to programmatically do it? or you could open word and save as ordinary document.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now