Windows RichTextBox Problem

viral patel 1 Reputation point
2020-12-08T10:51:27.09+00:00

Hi,

I am using windows RichText box to create RTF file for RTF input.
below is code,

RichTextBox RtfContent= new RichTextBox();
RtfContent.LoadFile(FileName,RichTextBoxStreamType.RichText);
in last getting RtfContent.RTF to write in file.

For some RTF inputs, it throws "External Component has thrown an error" in the RTFLoadFile method.

Is there any solution to resolve this issue ?

Note:

  • Loading with PlainText type working fine.
  • Same line of codes not giving any error in .NetFramework 4.6 but in .Net Framework 4.7 it throws error.

**

  • See below input RTF Content Causing issue,

**

{\rtf1\ansi\ansicpg1252\uc1\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fcharset0\fprq2{*\panose 02020603050405020304}Times New Roman{*\falt Times New Roman};}{\f1\fswiss\fcharset0\fprq2{*\panose 020b0604020202020204}Arial{*\falt Helvetica};}{\f35\fswiss\fcharset0\fprq2{*\panose 020b0604030504040204}Tahoma;}{\f39\froman\fcharset238\fprq2 Times New Roman CE{*\falt Times New Roman};}{\f40\froman\fcharset204\fprq2 Times New Roman Cyr{*\falt Times New Roman};}{\f42\froman\fcharset161\fprq2 Times New Roman Greek{*\falt Times New Roman};}{\f43\froman\fcharset162\fprq2 Times New Roman Tur{*\falt Times New Roman};}{\f44\froman\fcharset177\fprq2 Times New Roman (Hebrew){*\falt Times New Roman};}{\f45\froman\fcharset178\fprq2 Times New Roman (Arabic){*\falt Times New Roman};}{\f46\froman\fcharset186\fprq2 Times New Roman Baltic{*\falt Times New Roman};}{\f47\froman\fcharset163\fprq2 Times New Roman (Vietnamese){*\falt Times New Roman};}{\f49\fswiss\fcharset238\fprq2 Arial CE{*\falt Helvetica};}{\f50\fswiss\fcharset204\fprq2 Arial Cyr{*\falt Helvetica};}{\f52\fswiss\fcharset161\fprq2 Arial Greek{*\falt Helvetica};}{\f53\fswiss\fcharset162\fprq2 Arial Tur{*\falt Helvetica};}{\f54\fswiss\fcharset177\fprq2 Arial (Hebrew){*\falt Helvetica};}{\f55\fswiss\fcharset178\fprq2 Arial (Arabic){*\falt Helvetica};}{\f56\fswiss\fcharset186\fprq2 Arial Baltic{*\falt Helvetica};}{\f57\fswiss\fcharset163\fprq2 Arial (Vietnamese){*\falt Helvetica};}{\f389\fswiss\fcharset238\fprq2 Tahoma CE;}{\f390\fswiss\fcharset204\fprq2 Tahoma Cyr;}{\f392\fswiss\fcharset161\fprq2 Tahoma Greek;}{\f393\fswiss\fcharset162\fprq2 Tahoma Tur;}{\f394\fswiss\fcharset177\fprq2 Tahoma (Hebrew);}{\f395\fswiss\fcharset178\fprq2 Tahoma (Arabic);}{\f396\fswiss\fcharset186\fprq2 Tahoma Baltic;}{\f397\fswiss\fcharset163\fprq2 Tahoma (Vietnamese);}{\f398\fswiss\fcharset222\fprq2 Tahoma (Thai);}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;\red0\green102\blue102;}{\stylesheet{\ql \li0\ri0\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \snext0 \styrsid9127038 Normal;}{*\cs10 \additive \ssemihidden Default Paragraph Font;}{*\ts11\tsrowd\trftsWidthB3\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\tblind0\tblindtype3\tscellwidthfts0\tsvertalt\tsbrdrt\tsbrdrl\tsbrdrb\tsbrdrr\tsbrdrdgl\tsbrdrdgr\tsbrdrh\tsbrdrv \ql \li0\ri0\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs20\lang1024\langfe1024\cgrid\langnp1024\langfenp1024 \snext11 \ssemihidden Normal Table;}{*\cs15 \additive \ul\cf2 \sbasedon10 \styrsid9127038 Hyperlink;}{*\cs16 \additive \ul\cf12 \sbasedon10 \styrsid9127038 FollowedHyperlink;}{*\cs17 \additive \f35\fs22\expnd0\expndtw0\cf9 \sbasedon10 \ssemihidden \spersonal \scompose \styrsid9127038 EmailStyle17;}{\s18\ql \li0\ri0\sb100\sa100\sbauto1\saauto1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon0 \snext18 \styrsid9127038 Normal (Web);}{\s19\ql \li0\ri0\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon0 \snext19 \styrsid9127038 E-mail Signature;}}{*\revtbl {Unknown;}}{*\pgptbl {\pgp\ipgp2\itap0\li0\ri0\sb0\sa0}{\pgp\ipgp0\itap0\li750\ri0\sb300\sa0}}{*\rsidtbl \rsid1267987\rsid4288638\rsid9127038\rsid14224636}{*\xmlnstbl {\xmlns1 urn:schemas-microsoft-com:office:smarttags}}\paperw12240\paperh15840\margl1800\margr1800\margt1440\margb1440\gutter0 \widowctrl\ftnbj\aenddoc\noxlattoyen\expshrtn\noultrlspc\dntblnsbdb\nospaceforul\formshade\horzdoc\dgmargin\dghspace180\dgvspace180\dghorigin1701\dgvorigin1984\dghshow1\dgvshow1\jexpand\doctype2\viewkind5\viewscale100\pgbrdrhead\pgbrdrfoot\splytwnine\ftnlytwnine\htmautsp\nolnhtadjtbl\useltbaln\alntblind\lytcalctblwd\lyttblrtgr\lnbrkrule\nobrkwrptbl\snaptogridincell\allowfieldendsel\wrppunct\asianbrkrule\rsidroot4288638 \fet0{*\wgrffmtfilter 013f}{*\background {\shp{*\shpinst\shpleft0\shptop0\shpright0\shpbottom0\shpfhdr0\shpbxmargin\shpbxignore\shpbymargin\shpbyignore\shpwr0\shpwrk0\shpfblwtxt1\shpz0\shplid1025{\sp{\sn shapeType}{\sv 1}}{\sp{\sn fFlipH}{\sv 0}}{\sp{\sn fFlipV}{\sv 0}}{\sp{\sn fillType}{\sv 2}}{\sp{\sn fillBlip}{\sv {\pict\picscalex-1\picscaley-1\piccropl0\piccropr0\piccropt0\piccropb0\picw56444\pich106\picwgoal32000\pichgoal60\jpegblip\bliptag-1362886559{*\blipuid aec40061680f0f0063689db7951c1a37}\bin2743 リ・ JFIF H H ・ェPhotoshop 3.0 8BIM ・ x H H レ (・・・E G ( ・ H H リ ( d ' ` ・ 8BIM ・ H H 8BIM ・ 8BIM
8BIM'
8BIM ・ H /ff lff /ff 。劒 2 Z 5 - 8BIM ・ p  ・  ・  ・  ・ 8BIM 8BIM 8BIM @ @ 8BIM ・ } リ・ JFIF H H  'File written by Adobe Photoshopィ 4.0 ・ Adobe d ロ ・

                                                      タ         "       ン    ト ?                               

             3      ! 1 AQa "q・  贈アB#$ Rチb34rびC %担s5 「イ・D典dEツ」t6 メU稙・モu胚F'筈・米ヤ蔬・オナユ襄Vfv・ヲカニヨ踐7GWgw∠ァキヌラ銷                5     !1  AQaq"  2¢ 。アB#チRム・$b疵rCS cs4・  「イ・&5ツメD典」 dEU6te糘ウ・モu胚F筈・米ヤ蔬・オナユ襄Vfv・ヲカニヨ踐'7GWgw∠ァキヌレ          ? >恢  汗WI イ洙 _+、粥ェ _+、帖ェ _+、帖ェ _+、帖ェ _+、帖ェ _+、帖ェ _+、帖ル 8BIM                 'File written by Adobe Photoshopィ 4.0 ・ Adobe d     ロ ・             

                                                           "  "                                                      タ      @          ン   ネト 「                                

             s       ! 1AQ  a"q・2贈  アB#チRム・ b・rん%C4S弔イcsツ5D'謄ウ6 Tdtテメ・&・  

・EF、エVモU( ヤ蔬eu・・オナユ襄fv・ヲカニヨ踐7GWgw∠ァキヌラ銷8HXhx・ィクネリ顏)9IYiy甥ゥケノル鴿*:JZjz噛ェコハレ・ m ! 1A Q a" q¢2。ア・チム・B Rbr・$4C・担%「cイツ sメ5礇・T・
&6E 'dtU7ウテ()モ胚・、エトヤ蔬eu・・オナユ襄FVfv・ヲカニヨ踐GWgw∠ァキヌラ銷8HXhx・ィクネリ顏9IYiy甥ゥケノル鴿*:JZjz噛ェコハレ・レ ? ・糀・・ ・靃Ibサ・ ア['ュヌロTナw・ b」靃・ 莓+ソ漲 koS良メ濤ツ漑O|R ・ ; w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・・ U゚・ォソ・W タbョ ナ] 棺 w・* ル}}}{\sp{\sn fillBlipName}{\sv C:\'5cProgram Files\'5cCommon Files\'5cMicrosoft Shared\'5cStationery\'5cGlacier Bkgrd.jpg}}{\sp{\sn fillBlipFlags}{\sv 14}}{\sp{\sn fFilled}{\sv 1}}{\sp{\sn lineWidth}{\sv 0}}{\sp{\sn fLine}{\sv 0}}{\sp{\sn bWMode}{\sv 9}}{\sp{\sn fBackground}{\sv 1}}{\sp{\sn fLayoutInCell}{\sv 1}}}}}\sectd \linex0\endnhere\pgbrdropt32\sectlinegrid360\sectdefaultcl\sftnbj {*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang {\pntxta .}}{*\pnseclvl2\pnucltr\pnstart1\pnindent720\pnhang {\pntxta .}}{*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang {\pntxta .}}{*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang {\pntxta )}}{*\pnseclvl5\pndec\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{*\pnseclvl6\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}\pard\plain \s19\ql \li0\ri0\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\ipgp1 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\f35\fs20\cf9\lang1024\langfe1024\noproof\insrsid9127038 {*\bkmkstart _MailAutoSig}Hello,
\par
\par }\pard \s19\ql \li0\ri0\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\ipgp1\pararsid9127038 {\f35\fs20\cf9\lang1024\langfe1024\noproof\insrsid9127038 Now participating with }{\f35\fs20\cf9\lang1024\langfe1024\noproof\insrsid9127038 web rchant program is}{\f35\fs20\cf9\lang1024\langfe1024\noproof\insrsid9127038 :}{\f35\fs20\cf9\lang1024\langfe1024\noproof\insrsid9127038
\par FN\tab PITBT\tab Fairfield Inn and Suites by abc test {*\xmlopen\xmlns1{\factoidname place}}{*\xmlopen\xmlns1{\factoidname City}}Butler{*\xmlclose}{*\xmlclose}\tab {*\xmlopen\xmlns1{\factoidname place}}{*\xmlopen\xmlns1{\factoidname City}}Butler{*\xmlclose} {*\xmlopen\xmlns1{\factoidname State}}PA{*\xmlclose} {*\xmlopen\xmlns1{\factoidname country-region}}USA{*\xmlclose}{*\xmlclose}
\par }{\pard\plain \s19\ql \li0\ri0\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\ipgp1\pararsid9127038 \f35\fs20\cf9\lang1024\langfe1024\cgrid\noproof\langnp1033\langfenp1033\insrsid9127038 {{ {\f35\fs20\cf9\lang1024\langfe1024\noproof\insrsid9127038\charrsid9127038 }}}}{\f35\fs20\cf9\lang1024\langfe1024\noproof\insrsid9127038
\par }\pard \s19\ql \li0\ri0\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\ipgp1 {\f35\fs20\cf9\lang1024\langfe1024\noproof\insrsid9127038
\par
\par Best Regards,
\par
\par }{\i\f35\cf10\lang1024\langfe1024\noproof\insrsid9127038\rrsid4289691 {*\xmlopen\xmlns1{\factoidname PersonName}}tina{*\xmlclose} tmeyer
\par }{\f35\fs20\cf9\lang1024\langfe1024\noproof\insrsid9127038 home Airline Automation
\par Phone: 1615 Ext 2881
\par Fax: 1748
\par Email: help.desk@jaswant .com
\par }\pard\plain \ql \li0\ri0\sb100\sa100\widctlpar\wrapdefault\faauto\rin0\lin0\itap0\ipgp1 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\i\f1\fs16\cf9\lang1024\langfe1024\noproof\insrsid9127038 This communication contains information from abc International, Inc. that may be confidential. Except for personal use by the intended recipient, or as expressly authorized by the sender, any person who receives this information is prohibited from disclosing, copying, distributing, and/or using it. If you have received this communication in error, please immediately delete it and all copies, and promptly notify the sender. Nothing in this communication is intended to operate as an electronic signature under applicable law.}{\fs16\cf9\lang1024\langfe1024\noproof\insrsid9127038
\par }\pard \ql \li0\ri0\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 {\cf9\lang1024\langfe1024\noproof\insrsid9127038
\par }\pard\plain \s18\ql \li0\ri0\sb100\sa100\sbauto1\saauto1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\ipgp2 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\f1\fs20\cf17\insrsid9127038 {*\bkmkend _MailAutoSig}\~
\par }}

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,379 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,621 Reputation points
    2020-12-09T03:19:40.54+00:00

    Hi viralpatel-5130,
    I made a test with your code in in .NetFramework 4.6 and in in .NetFramework 4.7, They all worked fine.
    Here is my test code and RTF file.

    private void Form1_Load(object sender, EventArgs e)  
    {  
        RichTextBox RtfContent = new RichTextBox();  
        RtfContent.LoadFile(@"C:\Users\Desktop\t1.rtf", RichTextBoxStreamType.RichText);  
        this.Controls.Add(RtfContent);  
    }  
    

    t1.rtf
    46444-129.png
    And you said that Loading with PlainText type working fine. So I guess the problem is in your rtf file.
    PlainText means a plain text stream that includes spaces in places of Object Linking and Embedding (OLE) objects.
    RichText means a Rich Text Format (RTF) stream.
    In order to find the problem more accurately, please provide your RTF file and more details.
    As document said, you can also try to initialize the OpenFileDialog to look for RTF files.
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.