Solved

Client-Side JavaScript CopyFile problem

Posted on 2008-10-01
2
1,343 Views
Last Modified: 2012-06-21
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.


<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>
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now