| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

08-27-04, 09:45
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 96
|
|
|
Problems using DeleteFile()
|
|
Hi,
I am trying to use DeleteFile() to remove images when a records relating is deleted in the DB.
So far I can locate the file on the server using FileExists() but when I try to delete on my local IIS server (it is to go on host later) the script takes several minutes to execute, I don't get an error message but eventually IIS just crashes.
Here is the script I am using:
var fso= Server.CreateObject("Scripting.FileSystemObject");
//collect the full file path and escape the \
var file = Server.MapPath("\properties\\pop_images\\1.jpg")
//check if the file exost and delete if it does
if (fso.FileExists(file)==true)
{
fso.DeleteFile(file);
Response.Write('file was found and has been deleted');
}
else
{
Response.Write('Sorry this file does not exist');
}
Thanking you for any help,
olivier
|
|

08-27-04, 10:37
|
|
Useless...
|
|
Join Date: Jul 2003
Location: SoCal
Posts: 721
|
|
Correction in bold red
Addition in bold black
Code:
var fso= Server.CreateObject("Scripting.FileSystemObject");
//collect the full file path and escape the \
var file = Server.MapPath("/properties/op_images/1.jpg")
//check if the file exost and delete if it does
if (fso.FileExists(file)==true)
{
Dim objFile
Set objFile = fso.GetFile(file)
objFile.Delete
Set objFile = Nothing
Response.Write('file was found and has been deleted');
}
else
{
Response.Write('Sorry this file does not exist');
}
Set fso = Nothing
__________________
That which does not kill me postpones the inevitable.
|
|

08-27-04, 10:42
|
|
Useless...
|
|
Join Date: Jul 2003
Location: SoCal
Posts: 721
|
|
|
|
Correction in bold red
Addition in bold black
Code:
var fso= Server.CreateObject("Scripting.FileSystemObject");
//collect the full file path and escape the \
var file = Server.MapPath("/properties/op_images/1.jpg")
//check if the file exost and delete if it does
if (fso.FileExists(file)==true)
{
Dim objFile
Set objFile = fso.GetFile(file)
objFile.Delete
Set objFile = Nothing
Response.Write('file was found and has been deleted');
}
else
{
Response.Write('Sorry this file does not exist');
}
Set fso = Nothing
__________________
That which does not kill me postpones the inevitable.
|
|

08-28-04, 05:35
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 96
|
|
|
Getting error message when deleting file from folder
hi,
i have change the script following your advice, if I change the \ to a / the file is not found any more, however keeping the path as I had seems to work as the file is found.
i have change the script to use the GetFile() method and this is working but when I add objFile.Delete I get the following message:
Microsoft JScript runtime error '800a01b6'
Object doesn't support this property or method
on the main server that is, on my own iis it still gives me the same problem, could this be a problem of permissions not set properly?
Thanking you for your help,
Olivier
|
|

08-29-04, 15:52
|
|
Useless...
|
|
Join Date: Jul 2003
Location: SoCal
Posts: 721
|
|
Can you attach your code so we can take a look at what you're doing?
__________________
That which does not kill me postpones the inevitable.
|
|

08-30-04, 05:43
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 96
|
|
Hello,
here is the code I have below, it is in javascript :
Code:
var fso= Server.CreateObject("Scripting.FileSystemObject");
//collect the full file path
//this seems to be working OK as I get the message intended if the file is found
var file = Server.MapPath("\properties\\pop_images\\1.jpg")
//check if the file exist and delete if it does
if (fso.FileExists(file)==true)
{
var objFile;
objFile = fso.GetFile(file);
//I am not getting an error and the script seems to be running fine with the above
//I start getting error messages when I add objFile.Delete;
objFile.Delete;
Response.Write('<p>file was found and has been deleted</P>');
}
else
{
Response.Write('Sorry this file does not exist');
}
|
|

08-30-04, 11:33
|
|
Useless...
|
|
Join Date: Jul 2003
Location: SoCal
Posts: 721
|
|
Doh.. that was my bad.. Java... Is Response.Write a valid method of SSJS? Are you sure it's not dieing there? I don't use SSJS, but you might try changing it to Document.Write
__________________
That which does not kill me postpones the inevitable.
|
|

08-30-04, 21:13
|
|
Registered User
|
|
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
|
|
sholdn't it be...
objFile.Delete();
|
|

08-30-04, 23:30
|
|
Useless...
|
|
Join Date: Jul 2003
Location: SoCal
Posts: 721
|
|
Nice rok.. I missed that.. good catch.. I was thinking VB and not SSJS, so I didn't include the parens...
__________________
That which does not kill me postpones the inevitable.
|
|

08-30-04, 23:42
|
|
Registered User
|
|
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
|
|
hopefully it will help,... what is the actual error message??
|
|

09-03-04, 13:19
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 96
|
|
Hi,
my own IIS is still blocking on it, doesn't give a error, just takes minutes to mve and eventually crash. Might be something local, I am waiting for my host to update the permissions and will et you know if it is working,
Thanking you,
olivier
|
|

09-08-04, 10:25
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 96
|
|
Finally got to test on the host server, it is working perfectly,
Thank you very much,
Olivier
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|