473,395 Members | 1,443 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Saving textbox data as .txt file?

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
Nov 19 '05 #1
2 4928
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

Paul Evans wrote:
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

Nov 19 '05 #2
check out:
http://aspnet101.com/aspnet101/aspne...ode=createText

David Wier
MCP, MVP ASP.NET, ASPInsider
http://aspnet101.com
http://aspexpress.com
Coming Soon - Data Management Toolkit
Manage MSDE/SQL Server/MySQL/MS Access Databases from one location.
http://augustwind.com/augustwind/dmt.aspx


"Paul Evans" <pa*********@btinternet.com> wrote in message
news:OM****************@TK2MSFTNGP15.phx.gbl...
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

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: steve | last post by:
Hello, I am trying to import an image file into a form. This would be a persons picture saved in the same directory for every unique record. I don't have any problems making an action button to...
4
by: Ruy Castelli | last post by:
I created a ASP.NET page using C# and I'm using two components to access a MS-Access database, which are: - oleDbConnection - oleDataAdapter The MS-Access database is in the correct...
1
by: Nikhil Patel | last post by:
Hi, I bind a grid to a DataView object. I lose the reference to the underlying DataTable and the DataSet in a postback. Here is the code. Page_Load works fine and I am able to see the rows in...
1
by: Ruy Castelli | last post by:
I created a ASP.NET page using C# and I'm using two components to access a MS-Access database, which are: - oleDbConnection - oleDataAdapter The MS-Access database is in the correct directory...
0
by: AxOn | last post by:
Hi! I'm having trouble creating a save funktion. How can I save the contens of a new richTextBox that is created from an "external" class file? The open funktion looks like this: public void...
0
by: Gregaz | last post by:
I have a form in my project, which I open as a DialogBox. On that that form there are 3 TextBoxes. To one of them I want to write in a file path. To have it easier I have an OpenFileDialog control...
4
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my...
2
by: toddw607 | last post by:
Hi all! I am attempting to bring an SQL Server table into ASP.NET using the datagrid . I have set all cells to be a text box by which the user can just click on and edit the cell. I have a...
1
by: romcab | last post by:
Hi guys, I would like to ask your help about saving in ado.net. I was able to update it only on the display but when I check the database, it is not updated. I paste below my code and hopefully...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.