Outputting text to a file

  • Thread starter Thread starter Ash Phillips
  • Start date Start date
A

Ash Phillips

Ok, I'm not sure how I can explain this but here goes.

I have this program that uses a ListView for entries. What I have the
program doing is taking all the items from the listview, and writing them to
an HTML document.

Well what I did in VB6 was get all the info from the listview in a loop
routine and write the HTML into a text box. When that was completed I then
exported all the text from that text box to an html file.

In VB .NET however, I have a problem where (I think, but am not 100% sure)
all the HTML code can't fit into a text box so I can export it to a file.

Is there any way I can open the file and just keep writing lines of text to
the file instead of doing it to a textbox then to a file?

Hope that made sense :\

Thanks in advance,
Ash
 
Try using a System.IO.StreamWriter, like so:

-------------------------------------------------------------
Dim sw as System.IO.StreamWriter;

sw = new System.IO.StreamWriter("output.txt")

sw.WriteLine("Add this to file.")
sw.WriteLine("Also add this.")
sw.WriteLine("Finally, add this as well!")

sw.Close()
 
Ash,

I don't see your problem as you do it as now. (Your textbox has than to be
in the multiline status, what is in fact a kind of different approach of the
textbox than the single line because it has vbcrlf at the end of a line)

However I don't see the reason why you bring it first to a textbox.
This should go in the loop direct as well.

And when you change it use than directly that streamwriter as Fabricio shows
you.

I hope this helps?

Cor
 
Hi Ash,

in VB.NET you can do it identical.
You have to use a loop taking the values inside of listbox and write line
per line into the html file.

Kind Regards,

Jorge Serrano Pérez
MVP VB.NET
 
Ash,

Ash Phillips said:
Is there any way I can open the file and just keep writing lines of text
to
the file instead of doing it to a textbox then to a file?

File Access with Visual Basic Run-Time Functions:

Visual Basic Language Concepts -- File Access with Visual Basic Run-Time
Functions
<URL:http://msdn.microsoft.com/library/en-us/vbcn7/html/vbconProcessingFiles.asp>

- or -

..NET Framework Class Library -- 'FileStream' Class
<URL:http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemIOFileStreamClassTopic.asp>

..NET Framework Class Library -- 'StreamWriter' Class
<URL:http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemiostreamwriterclasstopic.asp>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top