c# - Encoding of rtf file -


i base64 encoded string represents rtf-file.

if original text representation (before base64 encode) see character sequence f¸r. should stand für, when displayed in viewer. header of rtf-file contains ansicpg1252 should encoding except otherwise changed (escape sequences, font definitions, ..).

my problem can't correctly decode base 64 string original representation. never f¸r anymore. instead have für or f\'fcr. through representation of umlaut wrong when displaying decoded rtf in viewer.

so original encoding of rtf-file? or going wrong here?

you can have sample file here. this base 64 encoded string get.

edit:

i don't have code encoding, think can reconstruct that. code this:

string path = "/some/path/ltxt1 kopie.rtf"; byte[] document = file.readallbytes(path); string base64string = convert.tobase64string(document); var isobytes = convert.frombase64string(base64string);  file.writealltext ("/some/path/sketch.rtf", system.text.encoding.getencoding("iso-8859-1").getstring(isobytes)); 

i tried change encoding, windows-1252 error (sketch: encoding name not supported, real project: array not null).

your issue not encoding of file. if run code , compare results, text same in each.

your issue source file ansi encoded , second file utf-8 encoded. however, rtf directive in text tells whatever interpreting rtf ansi encoded (the ansicpg1252 part). makes total mess of decoding due mismatch.

the simplest way around make sure write disc using matching encoding:

var iso = encoding.getencoding("iso-8859-1"); file.writealltext("/some/path/sketch.rtf", iso.getstring(isobytes), iso); 

or, more simply:

file.writeallbytes("/some/path/sketch.rtf", isobytes); 

Comments