...

View Full Version : Writing a file externally



ken_shoti
10-31-2006, 01:05 PM
i was searching for that script in this forum, but it seems to be lost or removed?

that script was kinda using activex or vbscript
it writes a .txt or a file to be saved to a location in the hard disk...
(it's not server-side)...can anyone repost that script?

_Aerospace_Eng_
10-31-2006, 04:29 PM
Will you be using an hta file to do this or will you be using a web page on the net somewhere? Its not possible to do this through a normal browser. Why are you wanting to create the text file in the first place?

ken_shoti
11-02-2006, 02:46 AM
hm...i'm working on something like:

typing some text and processing it using javascript, then i want to allow it to save it for backup purposes...

yes, it's possible, i once tried a code posted here, it works in creating a external text file saved locally on hard disk...

i can't find this script here anymore.....

btw, i'm working locally in my pc, client-side only!

brandonH
11-02-2006, 03:54 AM
that post you are talking about was one of my posts, lol.

lemme find it and i will re-post it.

using such a script, you must run it through a hta file (hyper text application) or something similar.
I have the VBscript version of it.....





<html>
<head></head>

<body>

<textarea id=textA rows=7 cols=60></textarea>
<input type=button value="write to file" name=Btn>
</body>
</html>

<script type=text/javascript>
function doit(){
return document.getElementById('textA').value;
}

</script>


<script language=VBscript>
Option Explicit
Dim objFSO, objFolder, objTextFile, objFile
Dim strDirectory, strFile, strText, f
Dim folfiles, fil, folder, i



Sub Btn_OnClick
strDirectory = "C:\folder\folder\"
strFile = "\filename.txt"
strText = doit()

' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
If strText = "False" then
MsgBox "Please fill in all fields before writing data to Database."
Else

' Check that the strDirectory folder exists

If objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Set folfiles = objFolder.Files
Else
f = split(strDirectory, "\")
for i=0 to UBound(f)
if i=0 then folder = f(i) else folder = folder & "\" & f(i)
if not objFSO.FolderExists(folder) then objFSO.CreateFolder(folder)
next
End If

If objFSO.FileExists(strDirectory & strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile(strDirectory & strFile)

End If
set objFile = nothing
set objFolder = nothing
Const ForAppending = 8
Const ForWriting = 2
Const ForReading = 1
Set objTextFile = objFSO.OpenTextFile(strDirectory & strFile, ForAppending, True)
' Writes strText every time you run this VBScript

objTextFile.WriteLine(strText)
objTextFile.Close
End If


End Sub
</script>







all the things higlighted are the parts you will need to change depending on wher ethe file is , what the files name is, and what you want to do to the file i.e. read from it, over write it, or append to it.

brandonH
11-02-2006, 03:56 AM
by the way, instead of saving it as a .html or .htm, just save it as .hta.


but you have to have I.E. on your computer for it to work. thats the downside to hta's

_Aerospace_Eng_
11-02-2006, 05:10 AM
hm...i'm working on something like:

typing some text and processing it using javascript, then i want to allow it to save it for backup purposes...

yes, it's possible, i once tried a code posted here, it works in creating a external text file saved locally on hard disk...

i can't find this script here anymore.....

btw, i'm working locally in my pc, client-side only!

Through a normal browser its not possible without getting any kind of security warnings. The fact that you are trying to do this worries me a little seeing as how you will be messing with users systems. Don't take on more than you can chew. If you can't code something yourself then don't do the project simple as that.

On a lighter note here is the thread that says how to do it using JS in an HTA file. I repeat an HTA file which is NOT a normal web browser.

http://www.codingforums.com/showthread.php?t=93439

ken_shoti
11-03-2006, 05:08 AM
thanx guys....
btw, it was your post aerospace, i even added a response there...
since i only code using javascript, then copy pasting some processed text can be a hassle, that's the reason i prefer a one button save!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum