Solved

javascript file.Delete Invalid argument

Posted on 2009-05-06
13
318 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
  • 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
 
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
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.

 

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

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

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

919 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

12 Experts available now in Live!

Get 1:1 Help Now