Solved

javascript file.Delete Invalid argument

Posted on 2009-05-06
13
322 Views
Last Modified: 2012-05-06
Using javascript, I can save a file or rename it without any problems using Scripting.FileSystemObject activex object.
However, if the user selects to delete one of these same files, I get an "Invalid Argument" error. It uses the exact same path/filename as the save and rename methods.
I can't seem to find any more detail on the error on the object.
Any ideas here ?
function remove_file(fn) {
 var myObject;
  myObject = new ActiveXObject("Scripting.FileSystemObject");
  var f;
  f = myObject.GetFile(this._uploadDirectory + fn); <====causes the error
  f.Delete();
}

Open in new window

0
Comment
Question by:MarshallMHS
[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
  • 6
  • 5
  • 2
13 Comments
 
LVL 12

Expert Comment

by:Gibu George
ID: 24316976
I thik you need to do like this

f = myObject.GetFile(this._uploadDirectory+"\" + fn);
0
 

Author Comment

by:MarshallMHS
ID: 24316995
Thanks, but that back-slash is included in the variable this._uploadDirectory.

0
 
LVL 12

Assisted Solution

by:Gibu George
Gibu George earned 100 total points
ID: 24317236
try an alert (f), post whats the output
0
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
LVL 63

Expert Comment

by:Zvonko
ID: 24317532
Add the output of the var conetent to see whether you have slashes in the right place:

  alert(this._uploadDirectory);

0
 

Author Comment

by:MarshallMHS
ID: 24317644
I can't do the alert on "f" because setting f is what causes the error.
I did inspect the var "this._uploadDirectory" and everything looks fine. It's the same path  used successfully in the save and rename methods that do work.

I did try "if (myObject.FileExists(this._uploadDirectory + fn))" and it returns false even though I can see the file in windows explorer. I am now totally confused  :)

Thanks for the reply !!
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 24317707
How is this scipt executed? Is it in a web server page or in a local html file or in a local hta file?
0
 

Author Comment

by:MarshallMHS
ID: 24317763
The javascript is in a web server page. To be more specific, I use an MS ajax scriptmanager, and load the script file in that.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 24317804
Are you sure you are executing the script on browser client side and the file is located on client disk?
Or are we talking about file shares?
Can we see one example of the variable content?

0
 

Author Comment

by:MarshallMHS
ID: 24317969
The file(s) are uploaded to the server.
I use a path like: d:\InetPub\application\docs\testfile.txt
I'm thinking that my client side script is looking for a local "D" drive when deleting ???
It does work locally, but not when I publish the site to the server. This is an intranet only site.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 24318024
I wonder that you even succeeded to create the ActiveXObject() on a web server page. That is never going to work. What do you want to delete? If you want to delete the server side files then you need not that JavaScript. You do it in ASP script, right?

 
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 24318117
Oh, and if you want to allow a web server page to delet local user files then you can forget it...
0
 

Author Comment

by:MarshallMHS
ID: 24318121
I am suffering from a mental block today. I use web services regularly and for some reason, today I'm thinking it has to be done with javascript.
My solution is that I use a web service to do the actual deletion.

Thanks for hanging in there with me !
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 400 total points
ID: 24318140
No problem.
See you.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

691 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