Just nu i M3-nätverket
Jump to content

Gör en txt fil av ett form?

Rickard M

Recommended Posts

Jag undrar om någon kan hjälpa mig med att skapa en txt fil från "File" som användaren skriver in i formet "File". Alltså jag vill att filen skall döpas efter det som användaren skriver in.Har jag inte förklarat tillräckligt återkommer jag.






Namn = Request("Namn")

File = Request("File")

ID_Category = Request("Dropmenu")





Set Connection = Server.CreateObject("ADODB.Connection")

Connection.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & server.mappath(accessdb)



If Namn = "" Then




If File = "" Then




If Description = "" Then




If ID_Category = "Select" Then




SQLStmt = "INSERT INTO tblScript"

SQLStmt = SQLStmt & "(Namn, File, ID_Category, Description)"

SQLStmt = SQLStmt & "VALUES('" & (Request.Form("Namn")) & "', '" & (Request.Form("File")) & "', '" & (Request.Form("Dropmenu")) & "', '" &(Request.Form("Description")) & "')"






End if

End if

End if

End if


Link to comment
Share on other sites

Kolla på följande artikel, kanske kan ge dig något....




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("scripting.FileSystemObject")


This line creates an object that is used for File Access


set myFile = fso.CreateTextFile("C:\test.txt", 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("my text here")

myFile.WriteLine("more text here")


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




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("Scripting.FileSystemObject")


Here we create our object again.


set f = fso.GetFile("C:\test1.txt")


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



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

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...