View Full Version : form to text file..!?
davidr
02-13-2005, 12:28 AM
Hi to all the asp developer :
i have asp page called file.asp with a form that contains file field(called
filemaker) it's posting to process.asp page , what i trying to do is to
capture the name of the file and create a text file that has the same name
of the file ( example : if i upload file named go.wav it create a text file
as go.txt ) and also insert the name of the file inside the go.txt file .
i know that it's simple scrip in asp can someone help me out with this
please ...
thanks allot for your help by advanced
David
jaywhy13
02-13-2005, 09:09 AM
Okay... uh... David... loose the bold... its hard on the eyes :thumbsup:
Neways straight to ur question...
Its pretty easy to get that done...
Its just a simple matter of getting the file name then using a number of methods like the split method to get the file name.
I'm not too sure about the aquisition of the file name.... but i think that the name of the file can be found by examining the contents of request.form
so me thinks you could do summin like:
thefilePath=request.form('filemaker')
'Say thefilePath holds c:\exmaple\file1.wav
'Then you could do summin like this
parts=Split(thefilePath,"\") 'creates an array by splittin the variable after each occurence of \
partsLength=ubound(parts,1) 'gets the upper bound
fileName=parts(partsLength) 'This should return file1.wav
fileParts=Split(fileName,".") 'Splitting the actual file name by the dot
fileName=fileParts(0)
fileExt=fileParts(1)
Hope this helps!!!! :thumbsup:
davidr
02-13-2005, 09:20 AM
you understand what i tring to do here is that , i only like to index files on the server without uploading them , user has FILE FIELD and he choose a file and he submit it to the proccess page , now i have to create .txt file with the name of the file the he submited and then inside the text file i have to add the file name he submited , i really approciate your help but i just couldn't find such scenario over the internet ..!
thanks allot for your help by adavcned
jaywhy13
02-13-2005, 03:43 PM
Okay consider the followin script from asp101 (http://www.asp101.com/resources/aspupload.asp)
<HTML>
<BODY>
<%
Set Upload = Server.CreateObject("Persits.Upload.1")
Upload.Save "c:\upload"
%>
Files:<BR>
<%
For Each File in Upload.Files
Response.Write File.Name & "=" & File.Path & " (" & File.Size & ")<BR>"
Next
%>
<P>
Other items:<BR>
<%
For Each Item in Upload.Form
Response.Write Item.Name & "=" & Item.Value & "<BR>"
Next
%>
</BODY>
</HTML>
You see there are two different collections.... Fool aroud with both and see if u can get either to do what u want to get done :D
davidr
02-13-2005, 06:38 PM
sorry but that's not what i trying to do over here ...
i'm not trying really upload the file i just like to creating the txt files with filefield , user choose the file from he's comuter and then hi submit it to the process.php page , then inside the server i have to get 1 file which called exactly the same name of the user file example ->( if user choose file called 1.wav and he submit the file , inside the server i like to get 1.txt and inside the 1.txt file should be 1.wav) , thats it .
thanks allot for your time by advanced ..
jaywhy13
02-13-2005, 06:43 PM
Well I don't kno? Thing is the <input type='file'> does not have a value attribute that you can play around with... Its not there for security reasons. So if what I posted didn't help before I don't kno David. If you're interested in a PHP soln why didn't u open ur thread there?
davidr
02-13-2005, 06:49 PM
anyway thanks allot for your help anyway , if anyone has solution in asp for creating txt files i will glad to hear it.
thanks you all by advanced.
jaywhy13
02-13-2005, 06:55 PM
http://www.juicystudio.com/tutorial/asp/files.asp
miranda
02-14-2005, 06:34 AM
You can use the script Jay showed you from asp101, just do NOT use the upload.save method and you will not upload anything. As long as the Save method is never called nothing is uploaded.
<HTML>
<BODY>
<%
Set Upload = Server.CreateObject("Persits.Upload.1")
'Upload.Save "c:\upload" ignoring this line keeps the file from uploading
%>
Files:<BR>
<%
For Each File in Upload.Files
Response.Write File.Name & "=" & File.Path & " (" & File.Size & ")<BR>"
Next
%>
<P>
Other items:<BR>
<%
For Each Item in Upload.Form
Response.Write Item.Name & "=" & Item.Value & "<BR>"
Next
%>
</BODY>
</HTML>
glenngv
02-14-2005, 11:44 AM
If the file will not be uploaded, then no need to use an upload component at all.
Just use a normal form (without multipart encoding which an upload form requires) and access the file field the way you do on other fields.
page 1:
<html>
<body>
<form name="f" method="post" action="page2.asp">
<input type="file" name="file1" />
<input type="submit" value="submit" />
</form>
</html>
page 2:
<%
response.write "Full path:" & request.form("file1")
'extract the filename from the retrieved full path (use InstrRev() and Mid() functions)
'create text file (Use FSO)
%>
davidr
02-14-2005, 11:58 AM
can you please continue the second page with fso cause i tried but it doesn't really work very well ...
glenngv thanks allor for your time i really approciate it .
glenngv
02-15-2005, 03:24 AM
http://www.devguru.com/Technologies/vbscript/quickref/filesystemobject_createtextfile.html
davidr
02-15-2005, 03:49 PM
Dear glenngv :
first thanks allot for your big help i really approciate it ..
<%
dim filesys, filetxt, getname, path
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile("c:\somefile.txt", True)
path = filesys.GetAbsolutePathName("c:\somefile.txt")
getname = filesys.GetFileName(path)
filetxt.WriteLine("Your text goes here.")
filetxt.Close
If filesys.FileExists(path) Then
Response.Write ("Your file, '" & getname & "', has been created.")
End If
%>
can you please help me with this one :
how can i change the somefile.txt to the submited filename ( if user submit 1.wav , it has to change to 1.txt )
and also how can i change the " Your text goes here" to the submited full file name ..!?
again thanks allot for you help , i really approciate it .
glenngv
02-16-2005, 02:19 AM
I thought you were only stucked to the FSO part and have already done the extraction of the filename and extension part of the retrieved full path? jaywhy13 already posted codes for that.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.