Reputation: 399
I am new to VB Code and struggling with Encode, Decode stuff. I need help with converting a text file from ANSI to UTF-16LE in VB.NET. This is what I have done so far. Later I am using BulkInsert for database operations and end up getting garbage data like
�000000000000000000000094409574896680&�
which is supposed to be
Ì095837491150000349192784421039109162%Î
FYI, the database columns are NVARCHAR.
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(filePath, System.Text.Encoding.Default)
Dim sw As System.IO.StreamWriter = New StreamWriter(pPath & pFilename & "_TEMP", True, System.Text.Encoding.Unicode)
While Not sr.EndOfStream
sw.writeLine(sr.readLine)
End While
sr.Close()
sw.Close()
Could anyone help, please? Thanks.
Upvotes: 1
Views: 2733
Reputation: 700272
You can use the ReadAllText
and WriteAllText
methods:
System.IO.File.WriteAllText(dest, File.ReadAllText(source, Encoding.Default), Encoding.Unicode)
Upvotes: 1