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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unable to kill file when accessed simultaneously

Status
Not open for further replies.

level1

Programmer
Apr 16, 2002
60
GB
Hello people.


Im doing a WEB type file manager, using the file system object, IIS, ASP and SQL97.

All functions are working fine. Although the system can also handle HTML files.

The problem i have is that every time im trying to Delete an HTML file that is been accessed by other users at same time i get the following error:

Microsoft VBScript runtime error '800a0046'
Permission denied

/pdh/concept_admin2.asp, line 53

line 53 is the delete command as follows:

fs.DeleteFile request("fullpathurl" & filedetails) & file_conv,true

I need to be able to delete a file no matter if somebody else is vewing it.

Also you get the following error if you try do delete it manualy:

There is a sharing violation the file may be in use.

So what im thinking is how is this possible when you use FTP (to delete files no matter if somebody else is accessing them?) and how can i make my thing to work?

Is it a coding issue???
is it a IIS issue?
Anybody can help please?



 
AFAIK, Windows will not let you delete a file while another user has it open, period.
Manually - in Win2K, go into Computer Management, connect to the machine where the file resides, go to file shares, and terminate the user's connection to the file.

It might be possible to do this using WMI, but being relatively new, documentation and examples are far and few between.

If you'd like to determine how many user's have the file open, use a script similar to the following, paying attention to the InUseCount property:
Jon Hawkins
 
I had the same problem deleting new created gif files that I needed to replace throught the code. I found that the best way to do this is by moving the file to a website trash folder and deleting all the files then creating the new one if this process did not return an error.

The code is a bit sloppy becuase I did it when i was a junior programmer...but it works, and you do not need to worry about a handle on the file because it seems to break the handle when you move the file and rename it. Then you can delete it.


Set FSO = CreateObject("Scripting.FileSystemObject")

'check if the file exists that you want to delete
IF FSO.FileExists (Server.MapPath("/yourvirtualsite") & "\Foldername\" & filename) Then

'move the file, for my purposes I rename it with a function that generates a random number in the process because if the same file name exists in the deleted folder it may not work
FSO.MoveFile (Server.MapPath("/yourvirtualsite") & "\Foldername\" & filename), Server.MapPath("/yourvirtualsite") & "\Deletedfoldername\" & RanFile()

//call this function to automatically delete the files in that folder.
Call DeleteFile()

END IF

Function DeleteFile ()
Dim virtualPath
Dim acctFolder
Dim Files
Dim File
Dim FSO

Set FSO = CreateObject("Scripting.FileSystemObject")
virtualPath = Server.MapPath("/yourvirtualsite") & "\Deletedfoldername\"
Set acctFolder = FSO.GetFolder(virtualPath)
Set Files = acctFolder.Files

If Files.Count <> 0 Then
For Each File in Files
FSO.DeleteFile virtualPath & File.Name
Next
end If

End Function

Function RanFile()
Dim Num
' Initialize generator twice to be sure will not duplicate
Randomize
Num=Cstr(Rnd)
Randomize
RanFile=Cstr(Int((9000 - 1 + 1) * Rnd + 1)) & Num & &quot;.HTML&quot;

End Function
 
unknown333,

A question.. If yoou try to move the file while it is beiung accessed, shouldn't you get a permission denied or action denied, just the same as if you were trying to delete a file while it is being accessed?


fengshui_1998
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top