Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Boxes - Send to a txt file and e-mail it??

Status
Not open for further replies.

johnharte

Technical User
Jul 26, 2001
41
GB
Is it possible to send info from a text box on submit to a txt file?

I would want it to do the following:

Send info from a text box to a file, eg:

Name: Jame T Kirk
Email: jame@tkirk.com
Nationality: American
Position: Starship Captain
etc, etc....

Then on Submit create a txt file which call's itself the name of the individual.ls2 (eg James T Kirk.ls2)

with content like so:

<name:[James T Kirk]>
<email:[jame@tkirk.com]>
<nationality:[American]>
<position:[Starship Captain]>

and then e-mail that file to a an address which is promted for?

Alot, I Know, But can anyone help?

Thanks,

John.
 
Tony,

For reading the attachment into an application..

John.
 
Hope this helps...

How to create a .txt file from ASP
--------------------------------------------------------

Ahh.. That feeling that comes from writing another article. You have to experience to believe it. Anyways, this tutorial is for the beginner to intermediate developer who wants to write to a text file. This purpose can be anywhere from storing text in a nice global format, to writing batch files to execute on the server. Now, belive it or not, I will NOT be linking this to a real world example. Why? Because the only one's I can think of involve ideas I plan to market. ;-) So now we are left with this.

Now, I will show you the basic commands for reading and writing, with a little bit of code snippits to keep everyone happy. It is very very simple. First, writing:

set FSO = Server.CreateObject(&quot;scripting.FileSystemObject&quot;)

This line creates an object that is used for File Access

set myFile = fso.CreateTextFile(&quot;C:\test.txt&quot;, true)

This creates a blank text file object for us to use.The CreateTextFile object creates a text file, based on what we specified. The first option specifies the location of the text file, while the second one states whether or not to create the file if one doesn't exist. Very simple methods.

Next, we do something simple

myFile.WriteLine(&quot;my text here&quot;)
myFile.WriteLine(&quot;more text here&quot;)

.WriteLine writes the text to the text file. What a novel idea! =D

myFile.Close

This closes the file, and makes it accessible to all (for the good old days of File Sharing). It also frees up memory.

Now for Reading:

First, we create an object, but not after defining some constants

Const ForReading = 1, ForWriting = 2, ForAppending = 8

This just allows us the different methods of working with text, when we have an open text file.

set fso = server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

Here we create our object again.

set f = fso.GetFile(&quot;C:\test1.txt&quot;)

Here we state that we will be manipulating the file C:\test1.txt . Moderately simple. Now we need to open it as a stream. Get ready, here comes the hard stuff ;-)

set ts = f.OpenAsTextStream(ForReading, -2)

This creates a text stream with our file. It is like a continous flow of information. Now we jsut read a line

TextStreamTest = ts.ReadLine

This code reads a line of information, and puts it into TextStreamTest. Pretty simple, isnt it?! I hope so. Anyway, I've discussed the code, and I shall let you go.

One last note. Let's say you wanted to read all the contents out a text file. Then you would do this

Do While not ts.AtEndOfStream
myText = myText & ts.ReadLine & vbCrLf
Loop

This tells it do a loop while there is still text, then read a line and add a line break. Very easy ;-)

How to create a .txt file from ASP


--------------------------------------------------------


How to send attachement email with ASP
--------------------------------------------------------
How to send attachement email with ASP
--------------------------------------------------------







Got ASP Error(s)? =
 
Argghhh

Help!

now that has thrown me!

I get this bit:

set FSO = Server.CreateObject(&quot;scripting.FileSystemObject&quot;)

set myFile = fso.CreateTextFile(&quot;C:\test.ls2&quot;, true)
myFile.WriteLine(&quot;my text here&quot;)
myFile.WriteLine(&quot;more text here&quot;)
myFile.Close

So If I wanted to put the field called &quot;name&quot; on the first line, would I replace (&quot;my text here&quot;) with:

(&quot;<input type=&quot;text&quot; name=&quot;textfield&quot; maxlength=&quot;50&quot; size=&quot;50&quot; value=&quot;<%=(lsp.Fields.Item(&quot;name:&quot;).Value)%>&quot;>&quot;)

Help, Help, Help!
 
I think what you want is:

myFile.WriteLine = lsp.Fields.Item(&quot;name:&quot;).Value

Cheech [Peace][Pipe]
The secret of life is honesty and fair dealing. If you can fake that, you've got it made.
Groucho Marx (1895-1977)
 
Thanks Cheech, I'll try that now!

John.

jharte@tmsdi.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top