Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem in deleting file

Status
Not open for further replies.

RakhiKalra

Programmer
Jun 6, 2003
41
0
0
IN
Hi,
I have a requierment of deleting a file. I am, writing the following code. when this code gets executed, the server processing starts and end with the servertimeout.
The code is as follows

dim strFullPath
strFullPath = "c:\inetpub\
dim objFileSystemObject
'Creating the object
Set objFileSystemObject=Server.CreateObject("Scripting.FileSystemObject")
'Delete the file
objFileSystemObject.DeleteFile(strFullPath)
'dispose the object
set objFileSystemObject=nothing


pls hellp

Rakhi
 
Does the IUSR account have permissions to delete the file on the webserver? Check the permissions of the \uploadedfiles directory.

Tony
________________________________________________________________________________
 
Yes i have checked the rights... i have given all rights to IUSR account. but still its not working.

Rakhi
 
are you getting a blank screen when the script runs? If so, do a view source and see if there is an error displayed at the bottom of the page.

Tony
________________________________________________________________________________
 
Try this...

Code:
dim strFullPath
strFullPath = "c:\inetpub\[URL unfurl="true"]wwwroot\mywebsite\uploadedfiles\myfile.txt"[/URL]

dim objFileSystemObject
'Creating the object
Set objFileSystemObject=Server.CreateObject("Scripting.FileSystemObject") 
'Delete the file
objFileSystemObject.DeleteFile(strFullPath) [b]true[/b]
'dispose the object
set objFileSystemObject=nothing

the boolean value forces the operation

Hope this helps!

gtg.jpg

GTG
 
Use server mappath

Code:
dim strFullPath
strFullPath = ServerMapPath("\uploadedfiles\myfile.txt")
'  ....
if objFileSystemObject.FileExists(strFullPath) then
    objFileSystemObject.DeleteFile(strFullPath)
end if



Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems

So long, and thanks for all the fish.
 
Hello RakhiKalra,

You keep saying not working not working... What testing code are you using leading you to such conclusion? Not only those lines you originally post, but the relevant part of interface/script triggering the file-deleting script expliciting client/server elements. (We can take your word on the IUSR_.)

regards - tsuji
 
*sigh* will try posting _AGAIN_...

your code :

dim strFullPath
strFullPath = "c:\inetpub\
dim objFileSystemObject
'Creating the object
Set objFileSystemObject=Server.CreateObject("Scripting.FileSystemObject")
'Delete the file
objFileSystemObject.DeleteFile(strFullPath)
'dispose the object
set objFileSystemObject=nothing

seems to be self defeating, creating and deleting the file at the same time? this is like me telling you to stand on a chair while i rip it out from under you, wouldn't make you very happy, same with your server.

steps to overcome :
validate IUSR_
use IfExists on the file before deleting it
make sure the file isn't in use .. by anyone ( notepad/browser ) OR by your code.. which in the supplied code the file is open and in use, and hence, undeletable.
skip the createfile if you're trying to delete it


[thumbsup2]DreX
aKa - Robert
 
DreXor,

You make a good point, make sure the file exists. I do not, however see where you think the file is being created. I see where he instantiates the FileSystem object, but he does not *create* the file in the code shown.

Rakhi,

In my testing, the file will still be deleted even if another program has it open (notepad in this case).

Are you sure the code is timing out? Errors in code will often show up simply as "Page Cannot Be Displayed" (Thank-you, Bill!). This is not neccessarily a time-out.

Here's my code which works just fine:

Code:
[highlight]<%[/highlight]
	dim objFileSys, strPath
	
	set objFileSys = server.CreateObject("Scripting.FileSystemObject")
	
	strPath = server.MapPath("/") & "\testfile.txt"
	
	response.Write strPath & "<br>"
	
	response.Write objFileSys.FileExists(strpath)
	if objFileSys.FileExists(strpath) then
		objFileSys.DeleteFile strPath
	end if
	
	set objFileSys = nothing
[highlight]%>[/highlight]

One more thing, and just a question here, no offence intended... did you check permissions in the File System or in IIS? Make sure IUSER_ has full permissions in the File System.

One more "one more thing": I know it souds trivial, and I may be wrong. I seem to remember that IIS can be picky about pathing. Example: in the file system, you would type a path with a "\" (i.e. c:\inetpub\ IIS may want something more along the lines of "c:/inetpub/ A simple replace function will take care of that for you. Again, I may be wrong, but it's worth a shot.

Code:
replace(strFullPath, "\", "/")

Hope this helps!

gtg.jpg

GTG
 
yeah my mistake after trying to post 4 times i kinda of got in a rush to post the code while the web site was responding, i had lost my clip board of the original post...

i was seeing the createobject as createtextfile in my rush to beat the failed post clock.

my apologies for my own confusion :)

[thumbsup2]DreX
aKa - Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top