Solved

Client-Side JavaScript CopyFile problem

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

863 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

26 Experts available now in Live!

Get 1:1 Help Now