G
Guest
Hi,
Im developing a webapplication that writes some "cache html files" to the filesystem.
But i ran into some problems, when i used TextWriter txw = File.CreateText(thefile)... txw.Write(stringtowrite)... txw.flust and close();
sometimes i got funny chars im my html...
After some testing i found that if i opened the file in notepad and saved it, the funny chars disappeared...
more testing... binary compare of the file before opened in notepad and saved and after... there vas a 3 bytes "magic number" in the file opned in notepad and saved...
it was 0xef 0xbb 0xbf ???? why not by default??
The workaround ( this cannot be the right way ):
BinaryWriter bw = new System.IO.BinaryWriter(System.IO.File.Create(filenameAndPath));
bw.Write(new byte[]{0xef,0xbb,0xbf});
bw.Write(sb.ToString().ToCharArray());
bw.Flush();
bw.Close();
This works but, IMO its crappy code....
Anybody know the right way of dooing just that???
Thanks in advance
Danny Hille
Im developing a webapplication that writes some "cache html files" to the filesystem.
But i ran into some problems, when i used TextWriter txw = File.CreateText(thefile)... txw.Write(stringtowrite)... txw.flust and close();
sometimes i got funny chars im my html...
After some testing i found that if i opened the file in notepad and saved it, the funny chars disappeared...
more testing... binary compare of the file before opened in notepad and saved and after... there vas a 3 bytes "magic number" in the file opned in notepad and saved...
it was 0xef 0xbb 0xbf ???? why not by default??
The workaround ( this cannot be the right way ):
BinaryWriter bw = new System.IO.BinaryWriter(System.IO.File.Create(filenameAndPath));
bw.Write(new byte[]{0xef,0xbb,0xbf});
bw.Write(sb.ToString().ToCharArray());
bw.Flush();
bw.Close();
This works but, IMO its crappy code....
Anybody know the right way of dooing just that???
Thanks in advance
Danny Hille