We help IT Professionals succeed at work.

How do i export listbox to notepad and print

2,035 Views
Last Modified: 2013-11-26
How do i export listbox to notepad and print in vb.net 2.0
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
1) Use a System.IO.StreamWriter and a For Each loop to write the ListBox text to a System.IO.FileStream.

2) Use a PrintDocument to print the text.

Bob
Shanmuga SundaramDirector of Software Engineering
CERTIFIED EXPERT

Commented:
Hi

You can also use (fso) filesystem object in your application to create a trace file.

This is another way that can be used to store the contents in a text file

Author

Commented:
Hi,
Can you give an example of code please
Shanmuga SundaramDirector of Software Engineering
CERTIFIED EXPERT

Commented:

Author

Commented:
is it for asp.net...m using vb.net
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
Something quick and easy:

Imports System.IO

Public Class ListBoxWriter

  Public Shared Sub Write(ByVal list As ListBox, ByVal fileName As String)

    Using stream As New FileStream(fileName, FileMode.Create)

      Using writer As New StreamWriter(stream)

        For Each item As String In list.Items
          writer.WriteLine(item)
        Next item

      End Using

    End Using

  End Sub

End Class

Sample usage:
   ListBoxWriter.Write(Me.ListBox1, "C:\My Documents\Output.txt")

Bob

Author

Commented:
Cheers TheLearnedOne but how do i print it?
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.