Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Nov 2005
    Posts
    230
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Writing a file externally

    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?

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Nov 2005
    Posts
    230
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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!

  • #4
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    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.....



    Code:
    <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.
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #5
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    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
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Quote Originally Posted by ken_shoti View Post
    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.

    no idea.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    Regular Coder
    Join Date
    Nov 2005
    Posts
    230
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •