Click to See Complete Forum and Search --> : How to show "\\files\charts\file019.xls"?
Michael Kam
04-24-2003, 09:19 AM
I want to show:
\\files\charts\file019.xls
by using the alert function.
But when i write code:
alert("\\files\charts\file019.xls");
it will shows:
\filescharts ile019.xls
May i know how to write code to display the output i want as stated above.
Thanks
Without ActiveX you cannot read from files. Also, backslash is an escape character:
alert("I said, \"hi!\""); returns: I said, "hi!" in an alert.
You have to use two backslashes: alert("file:///c|/my_folder/my_file.xls"); is better than: alert("c:\\my_folder\\my_file.xls");
Michael Kam
04-24-2003, 09:45 AM
OK, thanks for your reply.
Actually, i just want to display the file path by using the alert function, but not reading it from any source.
I mean, i have a server side ASP script to generate this client side javascript. The purpose is just let the user know the file path where the file located on a shared server drive.
I think is not practical to replace the escape character. Let say, we can do this, replace "\\files\charts\file019.xls" with
"\\\\files\\charts\\file019.xls", and probably it will display properly. But i don't know the whole list of characters that i need to replace. For example: /, ?, ...
So, i am asking, is there any function can do that automatically?
Like:
alert(somefunction("\\files\charts\file019.xls"));
It wil display:
\\files\charts\file019.xls
Quotes, aposrtrophes, backslashes need to be escaped. You can use, for example, a \n to start a new line:
alert("H\ni!"); will return:
H
i!
Doing this should work fine: alert("\\\\files\\charts\\file019.xls");
Michael Kam
04-24-2003, 10:14 AM
I understand what you mean. But the file path is not hardcoded. So, it is not practical for me to type:
alert("\\\\files\\charts\\file019.xls");
because my server script will return:
\\files\charts\file019.xls
and it is not always fixed to that file path. It depends on what the server return, and i will not know what the server script return.
what i have is:
\\files\charts\file019.xls
or
\\xxxx\yyyy\zzzz.xls
or
\\aaaa\bbbb\cccc.xls
or
??????
and how to make it to:
alert("\\\\files\\charts\\file019.xls");
or
alert("\\\\xxxx\\yyyy\\zzzz.xls");
or
alert("\\\\aaaa\\bbbb\\cccc.xls");
or
???????
?
I don't think is practical to load the file generated by the server (.asp), and save it into (.html), and then change the code return by the server from "\\files\charts\file019.xls" to "\\\\files\\charts\\file019.xls", and then save the html file, and put it back to the server, for every possible file path.
Try this:
var myVar = "\\files\charts\myFile.xls"; //variable from server
myVar = myVar.split("\\").join("\\\");
alert(myVar); // returns "\\\\files\\charts\\myFile.xls"
Charles
04-24-2003, 10:27 AM
You might have to use the escape() function serer side and the unescape() function client side. (http://developer.netscape.com/docs/manuals/js/client/jsref/toplev.htm#1063743).
Michael Kam
04-24-2003, 10:39 AM
Thanks a lot for you guys helping this.
I tried the script below, but it display nothing. Even the alert is not running.
<script language="javascript">
var myVar = "\\files\charts\myFile.xls"; //variable from server
myVar = myVar.split("\\").join("\\\");
alert(myVar); // returns "\\\\files\\charts\\myFile.xls"
</script>
My targeted client is using IE5.5 and above. Is that because of the versioning problem?
I can't use the unescape on the server, as it only permited to have VBScript on the ASP page (i mean this is the standard i have to follow for our company).
Hmmmm...... You're right. That won't work because those are backslashes---no matter how many you add.
Charles
04-24-2003, 11:31 AM
But the method that I mention above should work just fine.