Solved

javascript file.Delete Invalid argument

Posted on 2009-05-06
13
317 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
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 …
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

14 Experts available now in Live!

Get 1:1 Help Now