Solved

Client-Side JavaScript CopyFile problem

Posted on 2008-10-01
2
1,458 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 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

724 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