FreeTextBox

The no. 1 free ASP.NET HTML Editor.
Welcome to FreeTextBox Sign in | Join | Help
in Search

Problems copy/paste from MS Word

Last post 07-03-2009, 3:53 PM by rogal200. 2 replies.
Sort Posts: Previous Next
  •  06-30-2009, 11:07 AM 9959

    Problems copy/paste from MS Word

    Hello, I've had a few users do a 'copy' and 'paste' from MS Word into a FreeTextBox control.  When this text is later displayed on the screen, it has all of the idiotic MS Word formatting, which completely messes up the entire screen.

    Does anyone know of a good 'cleanup' routine, code, dll, something, that I can parse text through to strip out all of the nonsense that MS Word wraps around text?

    Thanks

  •  07-02-2009, 9:12 AM 9964 in reply to 9959

    Re: Problems copy/paste from MS Word

    The Professional version has the Clean Word feature which removes all the word formatting and replaces it with plain html.
  •  07-03-2009, 3:53 PM 9968 in reply to 9959

    Re: Problems copy/paste from MS Word

    I had the same problem, and I resolved it in this way, that after the user paste a text from MS Word and click "Save" button, I clean'up all html code from FTB like this:

    Code C#:
    System.Text.RegularExpressions.Regex objRegEx = new System.Text.RegularExpressions.Regex("<[^>]*>");
    string no_format = objRegEx.Replace(FreeTextBox1.Text, "");


    The worst disadvantage - it also compleately removes HTML formatting. There is one way to prevent, but it's a little bit silly. You can replace the HTML tags, before objRegEx.ReplaceTextFromMSWord, "") just like that:

    Code C#:
            string HTML = FreeTextBox1.Text;
            HTML = HTML.Replace("<br>", "*||*");
            HTML = HTML.Replace("<b>", "*--*");
            HTML = HTML.Replace("</b>", "*!-*");

            System.Text.RegularExpressions.Regex objRegEx = new  System.Text.RegularExpressions.Regex("<[^>]*>");

            HTML = objRegEx.Replace(HTML, "");
            HTML = HTML.Replace("*||*", "<br>");
            HTML = HTML.Replace("*--*", "<b>");
            HTML = HTML.Replace("*!-*", "</b>");

            FreeTextBox1.Text = HTML;
View as RSS news feed in XML
www.freetextbox.com