Write and append lines to file in VB.net

I have code to write to a file, but having trouble with appending.  I want the first line not to append, but the remaining lines to append.  I have this code...

Dim FILE_NAME As String = "\\server\folder\filename.txt"
Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
'My loop starts
                If i = 1 Then '2nd line to be written
                    objWriter = New System.IO.StreamWriter(FILE_NAME, True)
               End If
objWriter.WriteLine(strLineOfText)
'My loop ends
objWriter.Close()

Open in new window


Obviously I can't change the objWriter within the If statement, but I can't figure out how to get the append to work.  How can I get this code to work, or is there a better way to write and append to a file?
BrianAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
aehm, what loop and what lines? Can you please post a concise and complete example?
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
The following would write everything except the first item in your loop (assuming your loop is properly formed, of course):

Dim FILE_NAME As String = "\\server\folder\filename.txt"
Using objWriter As New System.IO.StreamWriter(FILE_NAME)
'My loop starts
                If i <>0 Then '2nd line to be written
                   objWriter.WriteLine(strLineOfText)
               End If
'My loop ends
End Using

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BrianAuthor Commented:
What I needed to do was this...
'My loop starts
                If i = 0 Then '2nd line to be written
                   objWriter.WriteLine(strLineOfText) 
               Else
                   objWriter.WriteLine(strLineOfText, True)
               End If
'My loop ends

Open in new window

BrianAuthor Commented:
Thanks for the help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.