Solved

Client-Side JavaScript CopyFile problem

Posted on 2008-10-01
2
1,393 Views
Last Modified: 2016-12-14
Hi.

I am want to use FSO to copy a local file over to the web server using client-side JavaScript.
The code below works fine if I uncomment target_spec, however when I try and build up a string dynamically to do the job I get a "Bad File Name" error.

Any ideas how I can correctly format the target_spec string to get it working?

Thanks, Ken.


[code]<html>
<head>
<title>Test1</title>
<script type="text/javascript">
function fnSaveServerImage()
{
    var server01 = "fvmweb994";
    var source_file = document.all.txtFile.value.replace(/\\/g,'\\\\');
    var target_file = "target001.jpg";
    var g_image_target_path = "F$\\TVP dotNET Web Applications\\TVP_SpeedWatch\\administration\\logos\\";

    var target_spec = "";
    target_spec += "\\\\\\\\";
    target_spec += server01 + "\\\\";
    target_spec += g_image_target_path.replace(/\\/g,'\\\\');
    target_spec += target_file;
   
    //var target_spec = "\\\\fvmweb994\\F$\\TVP dotNET Web Applications\\TVP_SpeedWatch\\administration\\logos\\target2.jpg";    

    var fso = new ActiveXObject("Scripting.FileSystemObject");

    fso.CopyFile(source_file, target_spec, true);
   
    alert("Done");    
}
</script>
</head>
<body>
<form id="form1" runat="server">
    <input type='button' value='Save as Server Image' onclick='fnSaveServerImage()' /><p>
    <input type="file" id="txtFile" size="60"/>
</form>
</body>
</html>[/code]
0
Comment
Question by:jonatec
2 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 22615020
try:
<html>
<head>
<title>Test1</title>
<script type="text/javascript">
function fnSaveServerImage()
{
    var server01 = "fvmweb994";
    var source_file = document.all.txtFile.value.replace(/\\/g,'\\\\');
    var target_file = "target001.jpg";
    var g_image_target_path = "F$\\TVP dotNET Web Applications\\TVP_SpeedWatch\\administration\\logos\\";  
    var target_spec = "";
    target_spec += "\\\\";
    target_spec += server01 + "\\";
    target_spec += g_image_target_path.replace(/\\/g,'\\');
    target_spec += target_file;
    
//    var target_spec = "\\\\fvmweb994\\F$\\TVP dotNET Web Applications\\TVP_SpeedWatch\\administration\\logos\\target2.jpg";     
    var fso = new ActiveXObject("Scripting.FileSystemObject"); 
    fso.CopyFile(source_file, target_spec, true);
    
    alert("Done");    
} 
</script>
</head>
<body>
<form id="form1" runat="server">
    <input type='button' value='Save as Server Image' onclick='fnSaveServerImage()' /><p>
    <input type="file" id="txtFile" size="60"/>
</form>
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:jonatec
ID: 31501998
Yep, fantastic, thanks very much!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question