Karuntos
Karuntos

Reputation: 61

Append text at the end of the line VB .NET

I want to append some texts in a file.

I used this code to append text from a file

Dim Lines As List(Of String) = ReadAllLines(Script_Path_DiskPart & File_MakeVDISK).ToList()
Lines.Insert(0, Frm_Login.AmountDisk & " Type=" & ChrW(34) & "EXPANDABLE" & ChrW(34))
System.IO.File.WriteAllLines(Script_Path_DiskPart & File_MakeVDISK, Lines)

And this is what I get after System.File.WriteAllLines(Script_Path_Diskpart & File_MakeVDISK, Lines)

Unexpected result:

enter image description here

Expected result:

enter image description here

Actually I want to use System.IO.File.Append... but I don't know how it works...

Upvotes: 0

Views: 794

Answers (1)

Craig
Craig

Reputation: 2474

It looks like instead of the Lines.Insert statement, you want to do something like this:

Lines(0) = Lines(0) & Frm_Login.AmountDisk & " Type=""EXPANDABLE"""

Note that you can escape a quote mark with another quote mark, instead of using the ChrW, hence the pair of doubled quotes "" around "EXPANDABLE".

Upvotes: 1

Related Questions