0

I'm writing XML to a text file in vB but the file contains a hidden "?" at the head of the file (it is visible on examining the parsed XML stream):

XML File

Code:= My.Computer.FileSystem.WriteAllText(DatFileName, GlobalVariables.DatContents, False, encoding:=System.Text.ASCIIEncoding.ASCII)

How can I suppress this or prevent it?? Thanks!

Patrick
  • 358
  • 2
  • 10
Mark
  • 13
  • 4
  • Possible duplicate of [Write text files without Byte Order Mark (BOM)?](https://stackoverflow.com/questions/2437666/write-text-files-without-byte-order-mark-bom) – Sani Huttunen Feb 26 '19 at 13:58
  • Hi Sani, not sure, the comments there suggest the BOM is not written but my problem is that it is written with WriteAllText... My.Computer.FileSystem.WriteAllText is an exception in this regard, guessing for backwards VB compatibility perhaps? File.WriteAllText defaults to UFT8NoBOM. – Mark Feb 26 '19 at 14:38
  • It is a garbage-in-garbage-out problem. Seeing the XML header back in the middle of an XML file is of course not correct. As written in the snippet, you get a question mark for any character that is not in the ASCII character set. Like the BOM. You'll have to focus on the code that determines the Payload value, it is broken, google "vb.net how to use xmlreader" for possibly useful hits. – Hans Passant Feb 26 '19 at 15:03
  • Not helpful Hans. Have come here to look for solutions - I am already aware it doesnt work. That is not debated. – Mark Feb 26 '19 at 22:28

0 Answers0