I want to be able to append text in the middle of a text file instead of at the end. What the below code does it searches for the [BrandIcons1] line, then it should immediately append text directly below [BrandIcons1]. But it appends at the end of the file.
I’m using vb.net 2003. There’s gotta be a way to do this.
Here’s what I have so far:
VB Code:
Private Sub btnWriteToFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWriteToFile.Click Dim oFile As System.IO.File Dim oRead As System.IO.StreamReader Dim oWrite As System.IO.StreamWriter Dim FILE_NAME As String = "C:\Program Files\WCS\Mobility\Config\mobility1.ini" Dim FILE_COPY As String = "C:\Program Files\WCS\Mobility\Config\mobility2.ini" Dim LineIn As String If oFile.Exists(FILE_NAME) = True Then oFile.Copy(FILE_NAME, FILE_COPY, True) ' ' Open and read an exisiting file oRead = oFile.OpenText(FILE_NAME) While oRead.Peek <> -1 LineIn = oRead.ReadLine() If LineIn = "[BrandIcons1]" Then oRead.Close() MsgBox(LineIn & " Found.") ' Write to an existing file oWrite = oFile.AppendText(FILE_NAME) oWrite.WriteLine("[BrandIcons]") oWrite.WriteLine("BE18=as1.bmp") oWrite.WriteLine("BE01=bu4.bmp") oWrite.WriteLine("BE02=") oWrite.WriteLine("---------") oWrite.Flush() oWrite.Close() Exit While End If End While MsgBox("Done!") Else MsgBox("File Does Not Exist: " & vbCrLf _ & FILE_NAME) End If Me.Close() 'End the program and close the form End Sub
The file to append Mobility1.ini
Any help would be appreciated.[MOBILITY]
back drive=d
standard header 1=Digital Matrix, Inc.
standard header 2=Budweiser
standard header 3=Holiday, CA
Last Backup Drive=d
dBev Compatibility=F
Sell Items Not In Product List=T
Auto Lost Placement Enabled=F
Auto Lost Placement Days=365
Use IBS Interface=F
Use IBS For Survey=F
Use IBS For WEARS=F
IBS Application Path=
IBS Window Title=IBS
Expired License Popup Msg Enabled=T
[BrandIcons1]
<append text information here>
[TCOMM]
host name=w55511
host ip=192.168.1.2
host login=wcs
host password=qjris
RAS Entry=Mobility
RAS phone number=555-1212
RAS login=np
RAS password=nkfl
RAS timeout=120
max tcomm number=99




Reply With Quote