Saving textbox data as .txt file?

P

Paul Evans

Hi,

Can anyone help me?

I have two text boxes, one single-line and one multiline.
I wish to save the text within the multiline textbox as a txt file,
with a file name by the text in the single-line textbox.

Does that make sense?
If the single-line textbox is 'helpme', I wish to create a txt file of the
multiline textbox called helpme.txt

I have found cound so far as follows, but this only adds text from a textbox
to an existing file.

<%@ Import Namespace="System.IO" %>

<Script Runat="Server">

Sub Button_Click( s As Object, e As EventArgs )
Dim objStreamWriter As StreamWriter

objStreamWriter = File.CreateText( MapPath( "myFile.txt" ) )
objStreamWriter.WriteLine( txtInput.Text )
objStreamWriter.Close
End Sub

</Script>



Can anyone help please?

Paul Evans
 
L

Lowell Heddings

First, it is bad design practice to allow a user to submit data that
will be used in a filename path. This opens the door for attacks on your
system.

But, I'd imagine you'd want to change this line to the following:

objStreamWriter = File.CreateText( MapPath( SingleLineTextBox.Text &
".txt" ) )


That should work, but again that is extremely bad design practice.

Lowell
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top