Create Text file as ANSI encoding Format
-
hi, i create text file through following code here argument FilePath contain full path of file and Data contains Contents which has been written to text file. if file already exist then it add data to previous contents of file otherwise it create a new text file
Private Sub CreateTextFile(ByVal FilePath As String, ByVal data As String) Dim oFile As System.IO.File Dim oWrite As System.IO.StreamWriter Dim oRead As System.IO.StreamReader Dim PreviousData As String = "" Dim CheckHypen As String If File.Exists(FilePath) Then oRead = oFile.OpenText(FilePath) While oRead.Peek <> -1 If PreviousData = "" Then PreviousData = oRead.ReadLine() Else PreviousData = PreviousData & ControlChars.NewLine & oRead.ReadLine() End If End While oRead.Close() End If oWrite = oFile.CreateText(FilePath) If PreviousData = "" Then oWrite.WriteLine(data) Else oWrite.WriteLine(PreviousData & ControlChars.NewLine & data) End If oWrite.Close() End Sub
i don't specify encoding format . some time text file is created with ANSI encoding format and sometime UTF-8 encoding format(dependent upon content). my problem is that i strictly create file as ANSI encoding.how it is possible? How can i set text file Encoding format to ANSI? any help will be appreciated.Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India)
-
hi, i create text file through following code here argument FilePath contain full path of file and Data contains Contents which has been written to text file. if file already exist then it add data to previous contents of file otherwise it create a new text file
Private Sub CreateTextFile(ByVal FilePath As String, ByVal data As String) Dim oFile As System.IO.File Dim oWrite As System.IO.StreamWriter Dim oRead As System.IO.StreamReader Dim PreviousData As String = "" Dim CheckHypen As String If File.Exists(FilePath) Then oRead = oFile.OpenText(FilePath) While oRead.Peek <> -1 If PreviousData = "" Then PreviousData = oRead.ReadLine() Else PreviousData = PreviousData & ControlChars.NewLine & oRead.ReadLine() End If End While oRead.Close() End If oWrite = oFile.CreateText(FilePath) If PreviousData = "" Then oWrite.WriteLine(data) Else oWrite.WriteLine(PreviousData & ControlChars.NewLine & data) End If oWrite.Close() End Sub
i don't specify encoding format . some time text file is created with ANSI encoding format and sometime UTF-8 encoding format(dependent upon content). my problem is that i strictly create file as ANSI encoding.how it is possible? How can i set text file Encoding format to ANSI? any help will be appreciated.Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India)
Following one line will do the all above mentioned task including appending and all ... My.Computer.FileSystem.WriteAllText("c:\x.txt", ControlChars.NewLine & "あだsだsd", True, System.Text.Encoding.Default) Third parameter "True" specifies appending and fourth parameter specifies ANSI depending upon ur systems ANSI code page.
-
Following one line will do the all above mentioned task including appending and all ... My.Computer.FileSystem.WriteAllText("c:\x.txt", ControlChars.NewLine & "あだsだsd", True, System.Text.Encoding.Default) Third parameter "True" specifies appending and fourth parameter specifies ANSI depending upon ur systems ANSI code page.
hi prasad, thanks for your support. i recently find method (AppendAllText) on internet during searching.i want to ask one more thing what is the difference between My.Computer.FileSystem.WriteAllText and AppendAllText method(of system.io.file object) can i use AppendAllText method ? thanks in advance
Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India)
-
hi prasad, thanks for your support. i recently find method (AppendAllText) on internet during searching.i want to ask one more thing what is the difference between My.Computer.FileSystem.WriteAllText and AppendAllText method(of system.io.file object) can i use AppendAllText method ? thanks in advance
Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India)
Hi Rupesh, Ofcource you can use it. Methods in My.Computer.FileSystem provides easy to use wrapper function to use the functionality implimented in System.Io.File. Regards Prasad
-
Hi Rupesh, Ofcource you can use it. Methods in My.Computer.FileSystem provides easy to use wrapper function to use the functionality implimented in System.Io.File. Regards Prasad
Thanks a lot
Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India)