-
January 30th, 2009, 11:26 PM
#1
Javascript; FileSystemObject;Localhost
hi,
im using this code
Code:
<script>
function load()
{
var fso, f, r;
var ForReading = 1, ForWriting = 2;
var str='Scripting.FileSystemObject';
fso = new ActiveXObject(str);
var file = 'c:/testfile.txt';
f = fso.OpenTextFile(file, ForWriting, true);
var text ='Hello world!';
f.Write(text);
f.Close();
alert('done');
}
load();
</script>
to create a file on my Hard Drive by saving the page simply in Desktop and execute it by double clicking the page
this is a simple html page.
but i want to create this file on my localhost by putting this html file in my localhost and i want to execute this file like
Code:
http://localhost/dir/file.htm
but it does not create the file on localhost with this code
Code:
<script>
function load()
{
var fso, f, r;
var ForReading = 1, ForWriting = 2;
var str='Scripting.FileSystemObject';
fso = new ActiveXObject(str);
var file = 'http://localhost/dir/testfile.txt';
f = fso.OpenTextFile(file, ForWriting, true);
var text ='Hello world!';
f.Write(text);
f.Close();
alert('done');
}
load();
</script>
and shows an error like
Code:
bad file name or number
please rate the post if this is useful. And also never forget to mark the thread as [Resolved] when your problem is solved
-
January 31st, 2009, 12:05 AM
#2
Re: Javascript; FileSystemObject;Localhost
I believe it is failing because it is expecting a path, not a URI. Have you tried using relative paths?
Meddle not in the affairs of dragons, human, for thou art crunchy and taste good with ketchup.
-
January 31st, 2009, 12:14 AM
#3
Re: Javascript; FileSystemObject;Localhost
im having the problem of path. I also tried Relative path like
Code:
var file = 'http://localhost/dir/testfile.txt';
but it creates the file on Desktop hahaha
i don't understand what exact path i should put on
var file
please rate the post if this is useful. And also never forget to mark the thread as [Resolved] when your problem is solved
-
January 31st, 2009, 10:45 AM
#4
Re: Javascript; FileSystemObject;Localhost
FileSystemObject looks at exactly what it says...the system's disk. It cannot tell what localhost is since it is not part of a web server. I'm sorry, but you are going to have to specify system relative path.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
January 31st, 2009, 01:57 PM
#5
Re: Javascript; FileSystemObject;Localhost
can you pls show me the correct way?
please rate the post if this is useful. And also never forget to mark the thread as [Resolved] when your problem is solved
-
January 31st, 2009, 03:34 PM
#6
Re: Javascript; FileSystemObject;Localhost
Take the http:// off the front, that indicates a URI or URL. Just use a relative path starting from the root location of your web app.
Meddle not in the affairs of dragons, human, for thou art crunchy and taste good with ketchup.
-
February 1st, 2009, 12:42 PM
#7
Re: Javascript; FileSystemObject;Localhost
i tried this now
Code:
var file = '//localhost/dir/testfile.txt';
and i got an error Permission Denied
how can i get it fixed pls?
please rate the post if this is useful. And also never forget to mark the thread as [Resolved] when your problem is solved
-
February 1st, 2009, 12:50 PM
#8
Re: Javascript; FileSystemObject;Localhost
Last edited by chunks; February 1st, 2009 at 12:53 PM.
Reason: Sorry Posted 2 Times So edited
please rate the post if this is useful. And also never forget to mark the thread as [Resolved] when your problem is solved
-
February 1st, 2009, 12:51 PM
#9
Re: Javascript; FileSystemObject;Localhost
or im doing something wrong here in the Relative PATH.
Code:
var file = '//localhost/dir/testfile.txt';
pls correct my path to get it working
please rate the post if this is useful. And also never forget to mark the thread as [Resolved] when your problem is solved
-
February 1st, 2009, 01:25 PM
#10
Re: Javascript; FileSystemObject;Localhost
As we have both stated many times, you cannot use localhost. You MUST use the relative path. That means c:\path\to\file.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
February 1st, 2009, 01:48 PM
#11
Re: Javascript; FileSystemObject;Localhost
but i want to keep the feedback of the users in a .txt file for my webpage.
is not that possible?
please rate the post if this is useful. And also never forget to mark the thread as [Resolved] when your problem is solved
-
February 1st, 2009, 07:11 PM
#12
Re: Javascript; FileSystemObject;Localhost
That is exactly what it is doing. For instance, let's say you're using IIS and the root for your web page is in c:\inetpub\wwwroot\myapp. You likely have a file in there called index.html (or index.php etc. etc.). When you use a *relative path*, it will start at the root directory of the web. Try to stay away from fully qualified paths (such as C:\my\path\my.file) as you will likely run into permission issues. If you specify the path "files/data.dat" then you will actually be referencing the file c:\inetpub\wwwroot\myapp\files\data.dat. I can't really define what a relative path is any clearer than that.
Meddle not in the affairs of dragons, human, for thou art crunchy and taste good with ketchup.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|