if the image is being displayed in a browser, then IIS might lock it for some time after someone has viewed it.
Main Topics
Browse All Topics am experiencing a problem using certain methods of the ASP file system object. It seems I can add files no problem, but if i try to edit them, or delete them, or even just access the files directly, my page just hangs and nothing happens. At this point, I have to close all my browsers, and stop and start the site, or it will not respond at all.
I am running my site in IIS 5.0 running on Windows XP (I have to test on my development machine, then push live to W2K server)
Here is a sample of the code I am using:
set objFSO = Server.CreateObject("Scrip
if objFSO.FileExists(Server.M
Response.Write "about to try to delete: " & strFilePath & " <-- can't delete file"
objFSO.DeleteFile strFilePath
end if
This is the output i get:
about to try to delete: files/{55572635-9AD9-4986-
So i know the file exists, it is getting into the loop.
However, all that happens it the page hangs, and will not continue loading at all. I need to close the browser, and stop and start the default website in IIS to get the page to load again.
The same thing happens when i try to rename a file, here is a sample of that code:
set objFSO = Server.CreateObject("Scrip
if objFSO.FileExists(Server.M
Response.Write "about to try to edit:<BR>" & Server.MapPath(strFilePath
set objFile = objFSO.GetFile (Server.MapPath(strFilePat
end if
I have previously asked this question here:
http://www.experts-exchang
I accepted the answer, as it made the problem go away.
BUT, then i went for lunch, and accepted one of microsofts XPs updates, and the problem is back. And worse yet, running the fix again did not help. I was convinced that it must be something to do with the permissions on the file and i tried changing them, the ones for the folder, permissions in IIS etc, and rebooted, and it was working for a while again, but then later stopped again, with no changes to the code.
A coworker tried it on his machine, and it was working for him as well for a while, then suddenly stopped for him as well (i'm not sure if he downloaded the update or not)
There are two other solutions suggested in the previous question:
-put the code in a .vbs file, and use create instead of server.createobject to make the FSO.
I don't think this is the answer, simply because i have done this many times using just ASP files, there should be no problem. Also, I'm writing a class, and i'd like it all to be encapsulated all within one file.
-use some error trapping to catch the error.
I don't think this is the solution, because my page is not even giving an error, or getting to the delete itself for that matter. It simply stops responding on the line:
strFilePath = Server.MapPath("/files/{54
I need to access this file to physically delete it.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
This is a bit strange, but MSDN shows a slightly different way to delete...maybe this is a typo, maybe not. I don't have XP here, so I can't test this, but they show it as the Delete method of the file object, not the file system object. So you use GetFile to get a reference to the file itself, then call the delete method on that file object:
Sub ManipFiles
Dim fso, f1, f2, s
Set fso = CreateObject("Scripting.Fi
Set f1 = fso.CreateTextFile("c:\tes
Response.Write "Writing file <br>"
' Write a line.
f1.Write ("This is a test.")
' Close the file to writing.
f1.Close
Response.Write "Moving file to c:\tmp <br>"
' Get a handle to the file in root of C:\.
Set f2 = fso.GetFile("c:\testfile.t
' Move the file to \tmp directory.
f2.Move ("c:\tmp\testfile.txt")
Response.Write "Copying file to c:\temp <br>"
' Copy the file to \temp.
f2.Copy ("c:\temp\testfile.txt")
Response.Write "Deleting files <br>"
' Get handles to files' current location.
Set f2 = fso.GetFile("c:\tmp\testfi
Set f3 = fso.GetFile("c:\temp\testf
' Delete the files.
f2.Delete
f3.Delete
Response.Write "All done!"
End Sub
Regards,
Mike Sharp
"Do you clear the file system object properly?"
Yes I do.
"if the image is being displayed in a browser, then IIS might lock it for some time after someone has viewed it."
Good Suggestion. however, i came in on monday morning, and tried, it and it still locks up on the delete. if this was the case (the file was locked), how would i go about forcing IIS to unlock the file? Or at least trap for the error anyway, i can't just have the page hang if someone tries to delete an image that was looked at recently.
Another thing that might happen is the file might be locked after uploading it. I'm doing an upload using the dundas upload component (which is working elsewhere for me), and making sure to release all resources using "set objFSO = nothing" etc at the end of the process, so I'm not sure how to determine if it's a locked file or not.
"Does it have to be named that? The brackets might be messing it up."
It doesn't HAVE to be named that, but it's very convenient to do so. The Dundas upload object generates a unique ID for saving files, so nothing is overwritten when files of the same name are uploaded. The unique ID starts with the { and ends with }, and i have coded to account for that. I have this same system working on another site, and i am able to rename, delete, copy etc with the files, so i don't think that could be it.
"This is a bit strange, but MSDN shows a slightly different way to delete..."
Yes, I have seen this as well, the delete can be performed on the object itself, or by the FSO.
Is there a reason you would use one or the other? Seems cleaner to me to use the FSO. In any case, the page crashes anyway, if i try to do it the other way, as soon as it hit's the line:
set objFile = objFSO.GetFile (Server.MapPath(strFilePat
which would be neccesary to delete the file using the alternate method.
Further information on the problem: I think there must be something not being closed properly, as my IIS is now not working. I tried accessing the page again, and i got an IIS error saying there were too many users connected. I tried stopping and starting the site (as i need to each time it hangs), and that didn't work, so i tried the web services, and got a message like "web services could not be stopped in a timely manner". Then i tried to stop and start the site again, and got an error "the requested control is not valid for this service". I tried actually restarting the IIS program, and my is flagged with an error now and will not respond at all.
So, i guess it's time for a reboot, and a complete check to make sure all objects and connections are closed.
I would still like to know why my page just hangs when trying to access the file though.
hmm.. just found something else:
why to use the FSO instead of the File:
DeleteFile
FSO.DeleteFile filename[,forceReadOnlyDel
Description
Deletes filename, which can contain wildcards (only the filename, not folder names).An error occurs if the filename is not found. [forceReadOnlyDelete] will force the file to be deleted if it's readonly.
http://www.sloppycode.net/
<%
'***************** DeleteFile
Set fso = CreateObject("Scripting.Fi
fso.DeleteFile "C:\afilename.*",true
' This deletes all files called "afilename", regardless of extension, and even if they are readonly files.
Set fso = Nothing
%>
Maybe this will help solve my problem, i'll try after the reboot.
icompass,
It sounds like you're having these issues because insuffient NTFS permissions on the folder containing the file to be deleted.
Note: I'm taking about NTFS security permissions not the permissions from the IIS management console.
To view the NTFS permissions, open Windows Explorer, right-click on the folder, select propertis, then click the security tab (if you don't see the security tab on XP, go control panel->folder options->View Tab scroll down the list and uncheck use simple file sharing).
From the secuirty tab you should see all the permission.
Add the following permission for now (just for testing):
click the add button, type in everyone, then click ok. Check the allow Full Control check box. Then click apply (don't close the properties sheet yet)
click on advanced button, then select Replace permissions on child objects, click ok on the advanced screen, then ok on the properties sheet.
Try to run your page, if it works post back, and I'll tell what users you need to give full control permission to on the live site (cuz you don't want to give everyone full control on a live server).
Hope this helps
Yes, I have already tried this as well. it's the IUSR_[computer name] account that needs read and write permissions. This was working for a while, but stopped. So i gave full control to everyone, and that worked for a while too, and then stopped. I made sure to propagate to all the child objects, and even gave full permissions to the entire innetpub root folder.
Still, *intermittently* i get this problem.
Yes, that's correct, the problem was in Norton AV, we found that 3 days ago, but i am awarding you the points anyway.
funny thing was, a lot of the time it would work, but sometimes it would hang. doesn't make me too confident of the script blocking abilities of NAV, if it only occasionally blocks them!
Business Accounts
Answer for Membership
by: rolftollerudPosted on 2003-09-06 at 15:42:06ID: 9303064
Do you clear the file system object properly?
At the end of the function put,
Set objFSO = Nothing