Trying to open a file on a network drive when user clicks an HTML button on a web page. When page loads, there is an error that states there's an invalid character on the line where I declare my variable. When I click the button, the error changes to "Object expected" but is on a line nowhere near any scripting or any HTML code related to scripting. Does my code look correct or no?
And, yes my button is calling the function on the "onclick" and "filepath" from VB code does have a value when I do a view source on the page.
<script language="javascript" type="text/javascript">
function OpenFile(){
var x = new ActiveXObject("WScript.Shell");
x.run(<%=filepath %>);
}
</script>
OK, I found out the reason for the invalid character error on the page load. It doesn't like the "filepath" from the VB side. I replaced with a text string to my local hard drive and the error goes away.
When I click the button now, the error is: "The system cannot find the file specified" even though the file exists.
Sorry, here's what the code looks like now. I have tried with and without the "file://" and both forward and back slashes with no luck.
<script language="javascript" type="text/javascript">
function OpenFile(){
var x = new ActiveXObject("WScript.Shell");
x.run("file://C:/Temp/123.jpg");
}
</script>
Yes, that is what I meant by opening (to open the file with the default program it is assigned to be opened with).
I still have the same problem. Error is "The system cannot find the path specified". Here is my code after your suggestion.
<script language="javascript" type="text/javascript">
function OpenFile(){
var x = new ActiveXObject("WScript.Shell");
x.Run("file://C:/Temp/123.jpg",1);
}
</script>
Yes, same result. The one big question, though, is will this work when trying to get a file from a network drive? If not, I might as well stop while I am ahead if I can only get it to work from a local hard drive.
Spoke with my supervisor. After I told him the problem, he suggested a different route. I am going to try it and see if I can get it to work. Thanks for your help. I'll reply later on if I come up with a solution.