PC Review


Reply
Thread Tools Rate Thread

¿ character added by My.Computer.FileSystem.WriteAllText

 
 
Manuel
Guest
Posts: n/a
 
      15th Aug 2005
Whenever I create/append a file using:

My.Computer.FileSystem.WriteAllText

It adds a ¿ character at the beginning of the file. Anyone knows why is
this happening?


 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      15th Aug 2005
"Manuel" <(E-Mail Removed)> schrieb:
> Whenever I create/append a file using:
>
> My.Computer.FileSystem.WriteAllText
>
> It adds a ¿ character at the beginning of the file. Anyone knows why is
> this happening?


Maybe a BOM is written at the beginning of the file (untested):

<URL:http://www.unicode.org/faq/utf_bom.html#BOM>

How do you determine that the character is added at the beginning of the
file?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

 
Reply With Quote
 
Manuel
Guest
Posts: n/a
 
      15th Aug 2005
> Maybe a BOM is written at the beginning of the file (untested):
I think this is the case because it only happens when I use a large string
to create/append the file. How can I turn it off?

> How do you determine that the character is added at the beginning of the
> file?


I open it with notepad and the character is there =p

"Herfried K. Wagner [MVP]" <hirf-spam-me-(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> "Manuel" <(E-Mail Removed)> schrieb:
>> Whenever I create/append a file using:
>>
>> My.Computer.FileSystem.WriteAllText
>>
>> It adds a ¿ character at the beginning of the file. Anyone knows why is
>> this happening?

>
> Maybe a BOM is written at the beginning of the file (untested):
>
> <URL:http://www.unicode.org/faq/utf_bom.html#BOM>
>
> How do you determine that the character is added at the beginning of the
> file?
>
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://classicvb.org/petition/>



 
Reply With Quote
 
Manuel
Guest
Posts: n/a
 
      15th Aug 2005
btw, it can be reproduced creating a large string and writing it to a file.
For example:
------------------------------------
Dim X As String = ""
Dim I As Integer
For I = 1 To 3000
Dim c As String = ""
Dim h As Integer
For h = 1 To 80
c &= "X"
Next
X &= c & vbCrLf
Next
My.Computer.FileSystem.WriteAllText("Test.txt", X, False)
------------------------------------

"Manuel" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>> Maybe a BOM is written at the beginning of the file (untested):

> I think this is the case because it only happens when I use a large string
> to create/append the file. How can I turn it off?
>
>> How do you determine that the character is added at the beginning of the
>> file?

>
> I open it with notepad and the character is there =p
>
> "Herfried K. Wagner [MVP]" <hirf-spam-me-(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> "Manuel" <(E-Mail Removed)> schrieb:
>>> Whenever I create/append a file using:
>>>
>>> My.Computer.FileSystem.WriteAllText
>>>
>>> It adds a ¿ character at the beginning of the file. Anyone knows why is
>>> this happening?

>>
>> Maybe a BOM is written at the beginning of the file (untested):
>>
>> <URL:http://www.unicode.org/faq/utf_bom.html#BOM>
>>
>> How do you determine that the character is added at the beginning of the
>> file?
>>
>> --
>> M S Herfried K. Wagner
>> M V P <URL:http://dotnet.mvps.org/>
>> V B <URL:http://classicvb.org/petition/>

>
>



 
Reply With Quote
 
Michael D. Ober
Guest
Posts: n/a
 
      16th Aug 2005
Using Manual's code, I got the following as the first three bytes of the
file

0xEF 0xBB 0xBF

Then the expected output of 80 characters lines of "X" were output. When I
did a debug.print on Left(X, 1) before the output, I received the expected
"X". I just report this to the VS 2005 beta team.

Mike Ober.

"Manuel" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> btw, it can be reproduced creating a large string and writing it to a

file.
> For example:
> ------------------------------------
> Dim X As String = ""
> Dim I As Integer
> For I = 1 To 3000
> Dim c As String = ""
> Dim h As Integer
> For h = 1 To 80
> c &= "X"
> Next
> X &= c & vbCrLf
> Next
> My.Computer.FileSystem.WriteAllText("Test.txt", X, False)
> ------------------------------------
>
> "Manuel" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> >> Maybe a BOM is written at the beginning of the file (untested):

> > I think this is the case because it only happens when I use a large

string
> > to create/append the file. How can I turn it off?
> >
> >> How do you determine that the character is added at the beginning of

the
> >> file?

> >
> > I open it with notepad and the character is there =p
> >
> > "Herfried K. Wagner [MVP]" <hirf-spam-me-(E-Mail Removed)> wrote in message
> > news:%(E-Mail Removed)...
> >> "Manuel" <(E-Mail Removed)> schrieb:
> >>> Whenever I create/append a file using:
> >>>
> >>> My.Computer.FileSystem.WriteAllText
> >>>
> >>> It adds a ¿ character at the beginning of the file. Anyone knows why

is
> >>> this happening?
> >>
> >> Maybe a BOM is written at the beginning of the file (untested):
> >>
> >> <URL:http://www.unicode.org/faq/utf_bom.html#BOM>
> >>
> >> How do you determine that the character is added at the beginning of

the
> >> file?
> >>
> >> --
> >> M S Herfried K. Wagner
> >> M V P <URL:http://dotnet.mvps.org/>
> >> V B <URL:http://classicvb.org/petition/>

> >
> >

>
>
>




 
Reply With Quote
 
Michael D. Ober
Guest
Posts: n/a
 
      18th Aug 2005

Still under review at MS. I'll post their response.

Mike.

"Michael D. Ober" <obermd.@.alum.mit.edu.nospam> wrote in message
news:%238$(E-Mail Removed)...
>
> Using Manual's code, I got the following as the first three bytes of the
> file
>
> 0xEF 0xBB 0xBF
>
> Then the expected output of 80 characters lines of "X" were output. When

I
> did a debug.print on Left(X, 1) before the output, I received the expected
> "X". I just report this to the VS 2005 beta team.
>
> Mike Ober.
>
> "Manuel" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > btw, it can be reproduced creating a large string and writing it to a

> file.
> > For example:
> > ------------------------------------
> > Dim X As String = ""
> > Dim I As Integer
> > For I = 1 To 3000
> > Dim c As String = ""
> > Dim h As Integer
> > For h = 1 To 80
> > c &= "X"
> > Next
> > X &= c & vbCrLf
> > Next
> > My.Computer.FileSystem.WriteAllText("Test.txt", X, False)
> > ------------------------------------
> >
> > "Manuel" <(E-Mail Removed)> wrote in message
> > news:%(E-Mail Removed)...
> > >> Maybe a BOM is written at the beginning of the file (untested):
> > > I think this is the case because it only happens when I use a large

> string
> > > to create/append the file. How can I turn it off?
> > >
> > >> How do you determine that the character is added at the beginning of

> the
> > >> file?
> > >
> > > I open it with notepad and the character is there =p
> > >
> > > "Herfried K. Wagner [MVP]" <hirf-spam-me-(E-Mail Removed)> wrote in message
> > > news:%(E-Mail Removed)...
> > >> "Manuel" <(E-Mail Removed)> schrieb:
> > >>> Whenever I create/append a file using:
> > >>>
> > >>> My.Computer.FileSystem.WriteAllText
> > >>>
> > >>> It adds a ¿ character at the beginning of the file. Anyone knows

why
> is
> > >>> this happening?
> > >>
> > >> Maybe a BOM is written at the beginning of the file (untested):
> > >>
> > >> <URL:http://www.unicode.org/faq/utf_bom.html#BOM>
> > >>
> > >> How do you determine that the character is added at the beginning of

> the
> > >> file?
> > >>
> > >> --
> > >> M S Herfried K. Wagner
> > >> M V P <URL:http://dotnet.mvps.org/>
> > >> V B <URL:http://classicvb.org/petition/>
> > >
> > >

> >
> >
> >

>
>
>
>




 
Reply With Quote
 
Michael D. Ober
Guest
Posts: n/a
 
      19th Aug 2005

MS Response: "By Design"

Description: Opened by Mike Ober on 2005-08-16 at 06:44:43

Execute the following code:

Module Module1

Sub Main()
Dim X As String = ""
Dim I As Integer
For I = 1 To 3000
Dim c As String = ""
Dim h As Integer
For h = 1 To 80
c &= "X"
Next
X &= c & vbCrLf
Next
Debug.Print(Left$(X, 1))
My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectorie
s.Desktop & "\Test.txt", X, False)
End Sub

End Module

The debug.print(Left$(X,1)) returns the expected "X". However, the first
three characters output to test.txt are "0xEF 0xBB 0xBF".

Version from the about box:
Microsoft Visual Studio 2005
Version 8.0.50215.44 (beta2.050215-4400)


Edited by Microsoft on 2005-08-18 at 10:06:23

Thank you for submitting this issue. I'm passing it to the feature team to
take a look.

-Shamez
Resolved as By Design by Microsoft on 2005-08-18 at 13:10:13

Thank you very much for submitting this issue.

This behavior is by design. As noted on Visual Studio 2005 Beta
Documentation
(http://msdn2.microsoft.com/library/27t17sxs(en-us,vs.80).aspx): "When no
encoding is specified, UTF-8 will be used.". The first 3 bytes you saw is
the Byte Order Mark (BOM) of UTF8. If you want to write the text out using
ASCII encoding, without any BOM, you can pass in System.Text.Encoding.ASCII
as the 4th parameter of WriteAllText.

Best regards,
Huy Nguyen, Visual Basic team.

Steps to Reproduce: Run the above code and view the output file in a binary
viewer. I used the VC 6++ editor from VS 6.
Actual Results: Binary view of output file's first line is
0xEF 0xBB 0xBF followed by 80 "X" characters as expected.

The rest of the file is correct.

Expected Results: 3000 lines of 80 "X" characters with a CRLF terminating
each line.
Attachments:
Workarounds:
Primary:
Duplicates:


==========
Somewhat counter intuitive for those of use used to standard ASCII, but in a
web and international language world, it is reasonable.

Mike.

"Michael D. Ober" <obermd.@.alum.mit.edu.nospam> wrote in message
news:0PRMe.6742$(E-Mail Removed)...
>
>
> Still under review at MS. I'll post their response.
>
> Mike.
>
> "Michael D. Ober" <obermd.@.alum.mit.edu.nospam> wrote in message
> news:%238$(E-Mail Removed)...
> >
> > Using Manual's code, I got the following as the first three bytes of the
> > file
> >
> > 0xEF 0xBB 0xBF
> >
> > Then the expected output of 80 characters lines of "X" were output.

When
> I
> > did a debug.print on Left(X, 1) before the output, I received the

expected
> > "X". I just report this to the VS 2005 beta team.
> >
> > Mike Ober.
> >
> > "Manuel" <(E-Mail Removed)> wrote in message
> > news:%(E-Mail Removed)...
> > > btw, it can be reproduced creating a large string and writing it to a

> > file.
> > > For example:
> > > ------------------------------------
> > > Dim X As String = ""
> > > Dim I As Integer
> > > For I = 1 To 3000
> > > Dim c As String = ""
> > > Dim h As Integer
> > > For h = 1 To 80
> > > c &= "X"
> > > Next
> > > X &= c & vbCrLf
> > > Next
> > > My.Computer.FileSystem.WriteAllText("Test.txt", X, False)
> > > ------------------------------------
> > >
> > > "Manuel" <(E-Mail Removed)> wrote in message
> > > news:%(E-Mail Removed)...
> > > >> Maybe a BOM is written at the beginning of the file (untested):
> > > > I think this is the case because it only happens when I use a large

> > string
> > > > to create/append the file. How can I turn it off?
> > > >
> > > >> How do you determine that the character is added at the beginning

of
> > the
> > > >> file?
> > > >
> > > > I open it with notepad and the character is there =p
> > > >
> > > > "Herfried K. Wagner [MVP]" <hirf-spam-me-(E-Mail Removed)> wrote in

message
> > > > news:%(E-Mail Removed)...
> > > >> "Manuel" <(E-Mail Removed)> schrieb:
> > > >>> Whenever I create/append a file using:
> > > >>>
> > > >>> My.Computer.FileSystem.WriteAllText
> > > >>>
> > > >>> It adds a ¿ character at the beginning of the file. Anyone knows

> why
> > is
> > > >>> this happening?
> > > >>
> > > >> Maybe a BOM is written at the beginning of the file (untested):
> > > >>
> > > >> <URL:http://www.unicode.org/faq/utf_bom.html#BOM>
> > > >>
> > > >> How do you determine that the character is added at the beginning

of
> > the
> > > >> file?
> > > >>
> > > >> --
> > > >> M S Herfried K. Wagner
> > > >> M V P <URL:http://dotnet.mvps.org/>
> > > >> V B <URL:http://classicvb.org/petition/>
> > > >
> > > >
> > >
> > >
> > >

> >
> >
> >
> >

>
>
>
>




 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
My.Computer.FileSystem.WriteAllText and disposing kimiraikkonen Microsoft VB .NET 5 6th Jan 2008 12:54 PM
Bug in My.Computer.FileSystem.WriteAllText =?Utf-8?B?Qm8gTWNJbHZhaW4=?= Microsoft Dot NET Framework 3 17th Aug 2007 07:34 AM
FileSystem.WriteAllText (broken methodl) Jared Microsoft Dot NET Framework Forms 3 12th Jul 2006 10:33 AM
ASP.NET 2: My.Computer.FileSystem.WriteAllText can write text file to any folder ? Tee Microsoft ASP .NET 7 9th Jul 2004 11:44 AM
Why are quotes being added to my document when using FileSystem.Write(1)? Christian Blackburn Microsoft VB .NET 4 14th Sep 2003 08:29 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:52 PM.