?
Solved

Client-Side JavaScript CopyFile problem

Posted on 2008-10-01
2
Medium Priority
?
1,487 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…
Suggested Courses

765 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