Click here to Skip to main content
15,881,092 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello! I have a complex c# program that gets data from multipe RTF files, merge them into one TXT file and I can search specific digits in it which are coming from serial port.

I have one very interesting problem, though.

I get 5-10 RTF files every day, but my browser can't access them. ALTHOUGH If I open them once, EDIT NOTHING, just save them again (even if on the same name). I can access them and read them with no problem.
I even tried other programming language (VB) but that didn't work either, so the files has some problem.
If i compare them in Total Commander that's the result: (AGAIN: SAME FILES, JUST OPENED AND SAVED AGAIN ON TH SAME NAME, NOTHING EDITED

THE FILE WHICH IS NOT WORKING STARTS WITH:
{\rtf1\ansi\deff0\deflang1024
{\fonttbl
{\f1\fswiss Arial CE;}
{\f2\fswiss Arial CE;}
{\f3\fswiss Arial CE;}
{\f4\fswiss Arial CE;}}
{\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\blue127;
\red0\green127\blue127;
\red0\green127\blue0;
\red127\green0\blue127;
\red127\green0\blue0;
\red127\green127\blue0;
\red127\green127\blue127;
\red192\green192\blue192;}
{\stylesheet
{\fs20\lang1033\snext0 Normal;}}
\viewkind1
\paperw11908\paperh16833\margl567\margr567\margt849\margb849
\gutter0\ftnbj\sectd\linex0\endnhere\pard\plain\fs20\lang1033


THE FILE THAT IS WORKING STARTS WITH:

{\rtf1\adeflang1025\ansi\ansicpg1250\uc1\adeff0\deff0\stshfdbch31505\stshfloch31506\stshfhich31506\stshfbi31507\deflang1038\deflangfe1038\themelang1038\themelangfe0\themelangcs0{\fonttbl{\f0\fbidi \froman\fcharset238\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f1\fbidi \fswiss\fcharset238\fprq2{\*\panose 020b0604020202020204}Arial;}
{\f34\fbidi \froman\fcharset1\fprq2{\*\panose 00000000000000000000}Cambria Math;}{\flomajor\f31500\fbidi \froman\fcharset238\fprq2{\*\panose 02020603050405020304}Times New Roman;}
{\fdbmajor\f31501\fbidi \froman\fcharset238\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\fhimajor\f31502\fbidi \froman\fcharset238\fprq2{\*\panose 02040503050406030204}Cambria;}
{\fbimajor\f31503\fbidi \froman\fcharset238\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\flominor\f31504\fbidi \froman\fcharset238\fprq2{\*\panose 02020603050405020304}Times New Roman;}
{\fdbminor\f31505\fbidi \froman\fcharset238\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\fhiminor\f31506\fbidi \fswiss\fcharset238\fprq2{\*\panose 020f0502020204030204}Calibri;}
{\fbiminor\f31507\fbidi \froman\fcharset238\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f42\fbidi \froman\fcharset0\fprq2 Times New Roman;}{\f41\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}
{\f43\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\f44\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}{\f45\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\f46\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}
{\f47\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}{\f48\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\f52\fbidi \fswiss\fcharset0\fprq2 Arial;}{\f51\fbidi \fswiss\fcharset204\fprq2 Arial Cyr;}
{\f53\fbidi \fswiss\fcharset161\fprq2 Arial Greek;}{\f54\fbidi \fswiss\fcharset162\fprq2 Arial Tur;}{\f55\fbidi \fswiss\fcharset177\fprq2 Arial (Hebrew);}{\f56\fbidi \fswiss\fcharset178\fprq2 Arial (Arabic);}
{\f57\fbidi \fswiss\fcharset186\fprq2 Arial Baltic;}{\f58\fbidi \fswiss\fcharset163\fprq2 Arial (Vietnamese);}{\flomajor\f31510\fbidi \froman\fcharset0\fprq2 Times New Roman;}{\flomajor\f31509\fbidi


anyone encountered ANYTHING like that before or has ANY idea to work it out?

Every help is much appreciated!
Best Regards,
Adam

What I have tried:

Everything
tried to access them various ways, none of them seems to work until i save them manually
Posted
Updated 21-Mar-16 21:53pm

The not working file specifies the font with index zero as default font (\deff0) but there is no matching entry in the font table (there are only entries for indexes 1 to 4).

So any text without an explicit reference to a font can't be rendered.
 
Share this answer
 
Comments
Ádám Tósaki 4-Mar-16 6:35am    
Thank you! Is there any way to still access these files?
Jochen Arndt 4-Mar-16 6:43am    
They are there and can be opened. So, yes you can access them by just opening them.

The best solution would be to fix the program that generates these invalid files.

If this is not possible, you may write a function that fixes the problems:
Open the file, read into memory, and check if the f0 font is missing. If so insert a f0 definition and write the file.
Ádám Tósaki 4-Mar-16 7:01am    
I can't fix the program that generates them because we get these lists from an other company.

I tried that but my C# application can't even read them into memory...it only works if i open in with word and click Save as....
Jochen Arndt 4-Mar-16 7:10am    
Then contact the other company and complain about it.

You should be able to read it into allocated memory as it is (binary). Using regex you can search for "{\fonttbl\s+{/f0".
If not found replace "{\fonttbl" with
"{\fonttbl{/f0 <your_font_definition_here>;}"
Ádám Tósaki 4-Mar-16 7:09am    
I just saw the files which are usable also uses \adeff0 and \deff0 so it must be something else.
I still can't access them anyhow with any application before I clicked save as in word
Okay. Officially solved, you will all laugh on me.

Instead of this:
C#
FolderBrowserDialog fd = new FolderBrowserDialog();
fd.SelectedPath = @"C:\BEVONT\";
fd.ShowDialog();
string path = fd.SelectedPath;

foreach (string file in Directory.GetFiles(path))
{
string contents = File.ReadAllText(file);
RichTextBox richTextBox1 = new RichTextBox();
richTextBox1.Rtf = contents + Environment.NewLine;
string plainText = richTextBox1.Text;
File.AppendAllText(@"N:\Kártyaellenőr\Konvert\Convert_" + DateTime.Now.ToString("yyyyMMdd") + ".txt", contents);
}


I just deleted some lines, and it's working now. Shame on me for not trying this before:
C#
FolderBrowserDialog fd = new FolderBrowserDialog();
fd.SelectedPath = @"C:\BEVONT\";
fd.ShowDialog();
string path = fd.SelectedPath;

foreach (string file in Directory.GetFiles(path))
{
string contents = File.ReadAllText(file);
File.AppendAllText(@"N:\Kártyaellenőr\Konvert\Convert_" + DateTime.Now.ToString("yyyyMMdd") + ".txt", contents);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900