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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

saving txt to a directory and not to a hard drive

Status
Not open for further replies.

nnn000555

Programmer
Jan 30, 2011
26
CA
Is it possible, and, if yes, then, how do you save a txt file to a directory and not to a hard drive? What is an example of a directory path to the destination?
 
This code in theory should work. But there might be a different syntax, which I can't seem to get right. May be somebody can help me?
frm.txt.value = window.location.pathname.toString().value
The code compiles, runs, but no result displayed.

Here is the full web page code for references.

<html>
<head>
</head>
<body>
<script type="text/javascript">
var c=0;
var file = "\\my-path.txt"
function addToFile() {
var fs = new ActiveXObject("Scripting.FileSystemObject")
var ts = fs.OpenTextFile(file,8,true,-2)
var t = document.getElementById("txt").value
var samplefile = "g:/musicshop/MyFile.txt"
alert("Saving... ")
c++;
ts.WriteBlankLines(3) ;
// Write a line.
ts.Write(c);


frm.txt.value = window.location.pathname.toString().value

frm.txt.value = ".,,,........"

ts.Close()
ts=fs=null
}
</script>
<form action="" name = "frm">
Click here:

<textarea id="txt" rows="5" cols="25"></textarea>

<input type="button" onclick="addToFile()" value="Save Information To Submit" />
</form>
</body>
</html>
 
I got a better code
Code:
var url = samplefile.location

frm.txt.value = url
frm.txt.value = ".,,,........"
but still no visibility of the result.
 
I'm confused again.

You say you want the storage path in the network location, but you are attempting to retrieve the path for the website holding the code, not the file being saved.

window.location would return "website.html" from say
Further more, pathname already returns a string so toString() is not necessary, and even if you would want to use it, toStrong does not return a "value" propery.
In addition to all that you are overwriting the value you are getting with ".,,,........" immediately after you get it.

Doing this:

frm.txt.value = window.location.pathname.

would output the websites file path. You can just throw functions together and expect to get a functional let alone meaningful result.
nnn000555 said:
->[network server]->[folder-path]-[file]
Actually, that's the path that I would like to recreate.

If I go by that post, then the path you want is the path you are using to save the file which you should already have as you are using to to save the file.
Code:
var file = "\\my-path.txt"
If that's not it, I just don't understand what you want.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Do you think this code will work on a third party web server? That's what I really want.
Code:
<html>
<head>
</head>
<body>
<script type="text/javascript">
var c=0;
var file = "\\my-path.txt"
function addToFile() {
var fs = new ActiveXObject("Scripting.FileSystemObject")
var ts = fs.OpenTextFile(file,8,true,-2)
var t = document.getElementById("txt").value
var samplefile = "filename.html"
alert("Saving... ")
c++;
ts.WriteBlankLines(3) ;
   // Write a line.
ts.Write(c);

var url = window.location.pathname

frm.txt.value = url
//frm.txt.value = ".,,,........"


ts.Close()
ts=fs=null
}
</script>
<form action="" name = "frm">
Click here:

<textarea id="txt" rows="5" cols="25"></textarea>

<input type="button" onclick="addToFile()" value="Save Information To Submit" />
</form>
</body>
</html>
 
I'm not sure how to answer that.

Assuming correct Activex permissions are set, it will open a file that resides somewhere in the local network of the PC that accessed the website. It will get the current value of a textbox, and then simply not use it again.

Set the samplefile variable to the string "filename.html"
Issue an alert box stating "Saving..."

Increase by one a variable set to 0 previously. Write that 1 into the open file, get the path of the website all this is running on set it as the value of the textbox, close the file and clear some variables.

If that all works for you, then it will work.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
My question is will window.location.pathname work on third party servers?
 
I tried the following:
Code:
var url = window.location.hostname + window.location.host + window.location.pathname 
+ window.location.href


frm.txt.value = url
//frm.txt.value = ".,,,........"


ts.Close()
ts=fs=null
}
</script>
<form action="" name = "frm">
Click here:

<span onclick="window.open( url,'_blank');"> ok</span>

<textarea id="txt" rows="5" cols="25"></textarea>

<input type="button" onclick="addToFile()" value="Save Information To Submit" />
The result was that the window opened once out of many times and showed the what i needed was g://musicshop/filename.html... how to accomplish finding the later one?
 
In the following code
Code:
var url = window.location.href


frm.txt.value = url
//frm.txt.value = ".,,,........"


ts.Close()
ts=fs=null
}
</script>
<form action="" name = "frm">
Click here:

<span onclick="window.open( url,'_blank');"> ok</span>
if I use
<span onclick="window.open( url,'_blank');"> ok</span>
it doesn't work, if i use
<span onclick="window.open( 'filename.html','_blank');"> ok</span>
it works.
How to make the url one work? Anybody knows why variable substitution did not work here?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top