Link to home
Start Free TrialLog in
Avatar of chadmanvb
chadmanvb

asked on

write an arraylist to a text file

How do I write this out to a text file?  the array is about 1000 lines long.

  Dim arrTSList As New Collection
    Sub Main()
        StartTSRestricted()
        Dim arrUserandName As New ArrayList

        For Each user In arrTSList
            arrUserandName.Add(GetUserInfo(user) & "," & user & "," & GetLastTime(user))
        Next
        arrUserandName.Sort()
 
    End Sub

'need to write out arrUserandName to a txt file
Avatar of deighton
deighton
Flag of United Kingdom of Great Britain and Northern Ireland image

use a streamwriter

see

http://msdn.microsoft.com/en-us/library/system.io.streamwriter.aspx

except you will do
for each in TheArrayList
SOLUTION
Avatar of s_chilkury
s_chilkury
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chadmanvb
chadmanvb

ASKER

//Try this
using System.IO

File.WriteAllLines("c:\TextFile.txt", arrUserandName)

That does not seem to work for an arraylist

I could not get it to work with streamwriter.  Do you have an example?

I tried this, but its not working either
  'Dim strTextFile As StreamWriter = New StreamWriter("c:\tsmemberstest.log")

        'For Each line In arrUserandName
            '    strTextFile.WriteLine(line)
        'Next
        'strTextFile.Close()
        'strTextFile.Dispose()
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
what doesn't work?  is it an error message or failure to compile

have you imported System.IO?

are you using a web site (ASP.net), you may have no authority to "c:\tsmemberstest.log".  It is a problem I had, make some directory and grant all rights to everyone and try writing to there.




Dim strTextFile As  System.IO.StreamWriter = New  System.IO.StreamWriter("c:\tsmemberstest.log")

 For Each MyLine as string In arrUserandName
             strTextFile.WriteLine(MyLine )
Next

strTextFile.Dispose()
Sorry, did not mean to close this.  wanted to split points with idle and chil.  Can you ples fix
Ok, got it working thanks so much for the help.