Hi Anthony,

It seems related to encoding mark (see
http://en.wikipedia.org/wiki/Byte_order_mark).

Just throwing few ideas into the air here as haven't really tried this
myself - but maybe you could try using StreamReader constructor overload
that accepts encoding so you could pass Encoding.Unicode to see if it solves
the issue.  If not, reading the file as stream of bytes and then use the
Encoding converter to convert it to string or strip off the byte order mark
at the beginning and convert then?

There is a similar topic discussed here
http://stackoverflow.com/questions/1835430/byte-order-mark-screws-up-file-reading-in-javabut
uses Java to explain the issue and resolution.


Cheers,
jano



On 15 November 2010 10:10, Anthony <[email protected]> wrote:

>  I have been using this function for years with no problem..now when i try
> to open a file(contains XML)..it returns an empty string even though it has
> text.  I have noticed that the XML  fie has some null charcaters at the
> begining..any suggestion?
>
> Public Shared Function GetFileContents(ByVal FullPath As String) As String
>
>        Dim stream As FileStream = Nothing
>
>        Dim strContents As String = String.Empty
>
>         Try
>
>             stream = File.Open(FullPath, FileMode.Open, FileAccess.Read)
>
>             Dim Tin As System.IO.StreamReader = 
> NewSystem.IO.StreamReader(stream)
>
>             strContents = Tin.ReadToEnd()
>
>             Tin.Close()
>
>             stream.Close()
>
>             Return strContents
>
>         Catch ex As Exception
>
>             Trace.WriteLine(ex.Message)
>
>             Return ""
>
>         Finally
>
>             If Not stream Is Nothing Then
>
>                 stream.Close()
>
>             End If
>
>         End Try
>
>     End Function
>
>  *****Is your website being 
> IntelliXperienced?*<http://www.intellixperience.com/signup.aspx>
> | www.yougoingmyway.com ?
> regards
> Anthony (*12QWERNB*)
>
> Is your website being IntelliXperienced?
>
>
>
>

Reply via email to