473,769 Members | 3,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Folders not deleting immediately

Hi I have a question that I hope someone can help me with. I have
created a web page that allows a user to upload an image with a
caption to my web server. Here is what happens when the user loads
the page:
1 - A temporary folder is created with that user's username here is an
example of the folder "c:\wwwroot\upl oad\tmp\usernam e".

2 - The user uploads the file it gets saved in the temp folder.

3 - The user hits the save button and the caption is dumped to the
database and then a new permanent folder is created (example "c:
\wwwroot\upload \article_43"). So now the file stored in the temp
folder gets copied to the permanent folder and then the content of the
temp folder is deleted along with the temp folder.

This is where I run into a problem. My temporary folder does not
delete immediately if at all. But it does not give me an error. If I
try to do anything with that folder from that point on I get an access
denied error. If I stop the IIS server the temp folder disappears and
everything is as it should be.

Either I'm not using the proper code to create or delete my files and
folders or its something to do with IIS or my web.config.

Here is my helper subs I use to create copy and delete.
=============== =============== =============== =============== ====

Public Sub CheckPath(ByVal Path As String)
Dim Mydirectory As New DirectoryInfo(P ath)
If Not Mydirectory.Exi sts Then
Mydirectory.Cre ate()
End If
End Sub

Public Sub CopyDir(ByVal FromPath As String, ByVal ToPath As
String)
Dim toDir As New DirectoryInfo(T oPath)
Dim fromDir As New DirectoryInfo(F romPath)
If toDir.Exists Then
toDir.Delete(Tr ue)
toDir.Create()
Else
toDir.Create()
End If
If fromDir.Exists Then
For Each theFiles As FileInfo In fromDir.GetFile s
Dim TargetFile As String = ToPath + "\" +
theFiles.Name
theFiles.CopyTo (TargetFile, True)
Next
End If
End Sub

Public Sub DelDir(ByVal DirPath As String)
Dim DelDir As New DirectoryInfo(D irPath)
If DelDir.Exists Then
DelDir.Delete(T rue)
End If
End Sub

Public Sub delFile(ByVal FullPath As String)
Dim TargetFile As New FileInfo(FullPa th)
If TargetFile.Exis ts Then
TargetFile.Dele te()
End If
End Sub

=============== =============== =============== =============== ====

Any help would be apreciated.

Thanks in advance
Eric

Feb 26 '07 #1
5 1282
On Feb 26, 9:29 pm, jaw...@hotmail. com wrote:
Hi I have a question that I hope someone can help me with. I have
created a web page that allows a user to upload an image with a
caption to my web server. Here is what happens when the user loads
the page:

1 - A temporary folder is created with that user's username here is an
example of the folder "c:\wwwroot\upl oad\tmp\usernam e".

2 - The user uploads the file it gets saved in the temp folder.

3 - The user hits the save button and the caption is dumped to the
database and then a new permanent folder is created (example "c:
\wwwroot\upload \article_43"). So now the file stored in the temp
folder gets copied to the permanent folder and then the content of the
temp folder is deleted along with the temp folder.

This is where I run into a problem. My temporary folder does not
delete immediately if at all. But it does not give me an error. If I
try to do anything with that folder from that point on I get an access
denied error. If I stop the IIS server the temp folder disappears and
everything is as it should be.

Either I'm not using the proper code to create or delete my files and
folders or its something to do with IIS or my web.config.

Here is my helper subs I use to create copy and delete.
=============== =============== =============== =============== ====

Public Sub CheckPath(ByVal Path As String)
Dim Mydirectory As New DirectoryInfo(P ath)
If Not Mydirectory.Exi sts Then
Mydirectory.Cre ate()
End If
End Sub

Public Sub CopyDir(ByVal FromPath As String, ByVal ToPath As
String)
Dim toDir As New DirectoryInfo(T oPath)
Dim fromDir As New DirectoryInfo(F romPath)
If toDir.Exists Then
toDir.Delete(Tr ue)
toDir.Create()
Else
toDir.Create()
End If
If fromDir.Exists Then
For Each theFiles As FileInfo In fromDir.GetFile s
Dim TargetFile As String = ToPath + "\" +
theFiles.Name
theFiles.CopyTo (TargetFile, True)
Next
End If
End Sub

Public Sub DelDir(ByVal DirPath As String)
Dim DelDir As New DirectoryInfo(D irPath)
If DelDir.Exists Then
DelDir.Delete(T rue)
End If
End Sub

Public Sub delFile(ByVal FullPath As String)
Dim TargetFile As New FileInfo(FullPa th)
If TargetFile.Exis ts Then
TargetFile.Dele te()
End If
End Sub

=============== =============== =============== =============== ====

Any help would be apreciated.

Thanks in advance
Eric
Looks like the file or directory is locked somewhere and you cannot
delete it until the server is restarted.

Try to delete all files from the directory one by one. Maybe it will
show you if there any problem with lock, or access...

So, instead of

DelDir.Delete(T rue)

this code

For Each fn As String in Directory.GetFi les(DirPath)
File.Delete(fn)
Next
DelDir.Delete

Feb 26 '07 #2
Thanks for the reply Alex. I've tried what you have suggested and
the files themself aren't locked they delete no problem. If i skip
the deletion of the folder itself everything works ok. I just dont
want to have a million empty folders after running the site for any
extended period of time. It's only the folders that seems locked.
Even if browse to the folder with windows explorer and I select it I
immediately get an access denied error.

Perhaps there is some type of auditing or health monitoring that is
being applies to the upload folder? If so is there a way to remove the
auditing from the upload folder and it's subfolders?

One thing I do know for sure is that its not an NTFS rights thing
cause it happens even on a fat32 system.

Any thoughts are appreciated.
Eric

Feb 26 '07 #3
On Feb 27, 12:17 am, jaw...@hotmail. com wrote:
Thanks for the reply Alex. I've tried what you have suggested and
the files themself aren't locked they delete no problem. If i skip
the deletion of the folder itself everything works ok. I just dont
want to have a million empty folders after running the site for any
extended period of time. It's only the folders that seems locked.
Even if browse to the folder with windows explorer and I select it I
immediately get an access denied error.

Perhaps there is some type of auditing or health monitoring that is
being applies to the upload folder? If so is there a way to remove the
auditing from the upload folder and it's subfolders?

One thing I do know for sure is that its not an NTFS rights thing
cause it happens even on a fat32 system.

Any thoughts are appreciated.
Eric
I found the reason.

This is due to File Change Notifications (FCN) and affected the .NET 2
only

http://blogs.msdn.com/toddca/archive...01/499144.aspx
http://www.vikramlakhotia.com/Deleti...ASPnet_20.aspx

So, don't delete directories at the runtime

By the way. If this is not working as expected, why don't you change
the logic? You can have only one initial directory at c:\wwwroot\uplo ad
\tmp\ and use it for all files from all users. To remember what the
user has uploaded you can use either session, or a database, or a
special naming of the files (e.g. article_43_thef ilename.jpg). Once a
new permanent folder is created you delete all files from the current
user...

Feb 27 '07 #4
Another option also is to don't do this under the application root. Or to
use a virtual directory.

This way ASP.NET 2.0 won't consider that you changed the application storage
layout...

"Alexey Smirnov" <al************ @gmail.coma écrit dans le message de news:
11************* *******@h3g2000 cw...legroup s.com...
On Feb 27, 12:17 am, jaw...@hotmail. com wrote:
>Thanks for the reply Alex. I've tried what you have suggested and
the files themself aren't locked they delete no problem. If i skip
the deletion of the folder itself everything works ok. I just dont
want to have a million empty folders after running the site for any
extended period of time. It's only the folders that seems locked.
Even if browse to the folder with windows explorer and I select it I
immediately get an access denied error.

Perhaps there is some type of auditing or health monitoring that is
being applies to the upload folder? If so is there a way to remove the
auditing from the upload folder and it's subfolders?

One thing I do know for sure is that its not an NTFS rights thing
cause it happens even on a fat32 system.

Any thoughts are appreciated.
Eric

I found the reason.

This is due to File Change Notifications (FCN) and affected the .NET 2
only

http://blogs.msdn.com/toddca/archive...01/499144.aspx
http://www.vikramlakhotia.com/Deleti...ASPnet_20.aspx

So, don't delete directories at the runtime

By the way. If this is not working as expected, why don't you change
the logic? You can have only one initial directory at c:\wwwroot\uplo ad
\tmp\ and use it for all files from all users. To remember what the
user has uploaded you can use either session, or a database, or a
special naming of the files (e.g. article_43_thef ilename.jpg). Once a
new permanent folder is created you delete all files from the current
user...

Feb 27 '07 #5
Thank you both for your help.

I do belive you are correct about the File Change Notification causing
this issue.

I will try the virtual directory thing first and if that gives a hard
time i guess i will need to put a few things back to the drawing board
and use one temp forlder for everyone.

Again thanks for your help,
Eric.

Feb 27 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
361
by: George | last post by:
VB.net 2003 standard, XP windows home edition. Installed first application OK today. When I removed the application via Control Panel, there were no problems and the app folders were deleted. But when I installed the app from a CD-ROM (Release folder is in D:), when I remove the app in Control Panel these problems occur: Control Panel does not delete the application folders. When I try to delete them I get message "Cannot delete file:...
5
2691
by: George | last post by:
VB.net 2003 standard, XP windows home edition. Installed first application OK today. When I removed the application via Control Panel, there were no problems and the app folders were deleted. But when I installed the app from a CD-ROM (Release folder is in D:), when I remove the app in Control Panel these problems occur: Control Panel does not delete the application folders. When I try to delete them I get message "Cannot delete file:...
9
10555
by: David Pratt | last post by:
Hi. I'm trying to clean files for packaging on mac using os.path.walk and want to clean the .DS_Store files that are hidden from view but could end up in code that I produce. # Clean mac .DS_Store if current_file == '.DS_Store': print 'a DS_Store item encountered' os.remove(f) My code walks the folders properly and print prints the statement when a
1
4747
by: semedao | last post by:
Hi all, I'm looking for some example , open source etc code that implement caching of files and folders with those requirments: 1. like every file system , I can write , read , delete etc files and folders , and put files into folders , sub folders etc. 2. every object in the cache can be accessed via: name , but also based on some unique ID , for example , the hash of the file data. 3. deleting folder will delete all it's sub folders &...
0
9586
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10043
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3956
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.