Huynh Bao
Huynh Bao

Reputation: 121

File format is not valid Richtextbox c#

Error: File format is not valid in Richtextbox.

My code here:

var webClient = new WebClient(); //Make sure to reference System.Net
richTextBox1.Rtf = webClient.DownloadString("http://koolkool.freevnn.com/tool/Documents/invitePK.rtf")

Please help me. Image error here: enter image description here

Upvotes: 6

Views: 3387

Answers (2)

MV Sreedhar
MV Sreedhar

Reputation: 359

Below lines are from MSDN reference source.

string str = Encoding.Default.GetString(bytes);
if (!SZ_RTF_TAG.Equals(str)) // SZ_RTF_TAG ="{\\rtf";
    throw new ArgumentException(SR.GetString(SR.InvalidFileFormat));

if the value you are assigning is not starting with "{\rtf" microsoft will throw the exception.

If you are assigning the value which starts with "{\rtf" and still facing the issue then issue could be with your OS. Similar issues were started occurring with windows version 1803.

If you have windows version 1803 then disabling the beta feature will solve the issue.

To Disable Beta: unicode UTF-8 for world wide language support Start=> Region & Language settings => Related settings -> Additional date, time & regional settings => Region -> Change date, time or number formats => select Administrative tab => Click on Change System Locale.. => UnCheck Beta: unicode UTF-8 for world wide language support => restart your system.

Upvotes: 4

lc.
lc.

Reputation: 116498

Well, let's use PowerShell and take a look at what you're actually downloading:

PS > $wc = New-Object System.Net.WebClient
PS > $wc.DownloadString("http://koolkool.freevnn.com/tool/Documents/invitePK.rtf")
<html><body><script type="text/javascript" src="/aes.js" ></script><script>function toNumbers(d){var e=[];d.replace(/(.
.)/g,function(d){e.push(parseInt(d,16))});return e}function toHex(){for(var d=[],d=1==arguments.length&&arguments[0].co
nstructor==Array?arguments[0]:arguments,e="",f=0;f<d.length;f++)e+=(16>d[f]?"0":"")+d[f].toString(16);return e.toLowerC
ase()}var a=toNumbers("f655ba9d09a112d4968c63579db590b4"),b=toNumbers("98344c2eee86c3994890592585b49f80"),c=toNumbers("
e1b925425726f4245ffe50e9fafc1f50");document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37
23:55:55 GMT; path=/";location.href="http://koolkool.freevnn.com/tool/Documents/invitePK.rtf?ckattempt=1";</script><nos
cript>This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript
support</noscript></body></html>
PS >

Whoops. It looks like RichTextBox doesn't know what to do with that HTML string. Bad server. I ask for an .rtf resource, and you give me some JavaScript junk?

Upvotes: 5

Related Questions