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(GetUser Info(user) & "," & user & "," & GetLastTime(user))
Next
arrUserandName.Sort()
End Sub
'need to write out arrUserandName to a txt file
Dim arrTSList As New Collection
Sub Main()
StartTSRestricted()
Dim arrUserandName As New ArrayList
For Each user In arrTSList
arrUserandName.Add(GetUser
Next
arrUserandName.Sort()
End Sub
'need to write out arrUserandName to a txt file
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
//Try this
using System.IO
File.WriteAllLines("c:\Tex tFile.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?
using System.IO
File.WriteAllLines("c:\Tex
That does not seem to work for an arraylist
I could not get it to work with streamwriter. Do you have an example?
ASKER
I tried this, but its not working either
'Dim strTextFile As StreamWriter = New StreamWriter("c:\tsmembers test.log")
'For Each line In arrUserandName
' strTextFile.WriteLine(line )
'Next
'strTextFile.Close()
'strTextFile.Dispose()
'Dim strTextFile As StreamWriter = New StreamWriter("c:\tsmembers
'For Each line In arrUserandName
' strTextFile.WriteLine(line
'Next
'strTextFile.Close()
'strTextFile.Dispose()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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: \tsmembers test.log")
For Each MyLine as string In arrUserandName
strTextFile.WriteLine(MyLi ne )
Next
strTextFile.Dispose()
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:
For Each MyLine as string In arrUserandName
strTextFile.WriteLine(MyLi
Next
strTextFile.Dispose()
ASKER
Sorry, did not mean to close this. wanted to split points with idle and chil. Can you ples fix
ASKER
Ok, got it working thanks so much for the help.
see
http://msdn.microsoft.com/en-us/library/system.io.streamwriter.aspx
except you will do
for each in TheArrayList