Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Folders not deleting immediately

Reply
Thread Tools

Folders not deleting immediately

 
 
jawloc@hotmail.com
Guest
Posts: n/a
 
      02-26-2007
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\upload\tmp\username".

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(Path)
If Not Mydirectory.Exists Then
Mydirectory.Create()
End If
End Sub

Public Sub CopyDir(ByVal FromPath As String, ByVal ToPath As
String)
Dim toDir As New DirectoryInfo(ToPath)
Dim fromDir As New DirectoryInfo(FromPath)
If toDir.Exists Then
toDir.Delete(True)
toDir.Create()
Else
toDir.Create()
End If
If fromDir.Exists Then
For Each theFiles As FileInfo In fromDir.GetFiles
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(DirPath)
If DelDir.Exists Then
DelDir.Delete(True)
End If
End Sub

Public Sub delFile(ByVal FullPath As String)
Dim TargetFile As New FileInfo(FullPath)
If TargetFile.Exists Then
TargetFile.Delete()
End If
End Sub

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

Any help would be apreciated.

Thanks in advance
Eric

 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      02-26-2007
On Feb 26, 9:29 pm, (E-Mail Removed) 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\upload\tmp\username".
>
> 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(Path)
> If Not Mydirectory.Exists Then
> Mydirectory.Create()
> End If
> End Sub
>
> Public Sub CopyDir(ByVal FromPath As String, ByVal ToPath As
> String)
> Dim toDir As New DirectoryInfo(ToPath)
> Dim fromDir As New DirectoryInfo(FromPath)
> If toDir.Exists Then
> toDir.Delete(True)
> toDir.Create()
> Else
> toDir.Create()
> End If
> If fromDir.Exists Then
> For Each theFiles As FileInfo In fromDir.GetFiles
> 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(DirPath)
> If DelDir.Exists Then
> DelDir.Delete(True)
> End If
> End Sub
>
> Public Sub delFile(ByVal FullPath As String)
> Dim TargetFile As New FileInfo(FullPath)
> If TargetFile.Exists Then
> TargetFile.Delete()
> 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(True)

this code

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

 
Reply With Quote
 
 
 
 
jawloc@hotmail.com
Guest
Posts: n/a
 
      02-26-2007
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

 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      02-27-2007
On Feb 27, 12:17 am, (E-Mail Removed) 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\upload
\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_thefilename.jpg). Once a
new permanent folder is created you delete all files from the current
user...

 
Reply With Quote
 
Patrice
Guest
Posts: n/a
 
      02-27-2007
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" <(E-Mail Removed)> a écrit dans le message de news:
http://www.velocityreviews.com/forums/(E-Mail Removed)...
> On Feb 27, 12:17 am, (E-Mail Removed) 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\upload
> \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_thefilename.jpg). Once a
> new permanent folder is created you delete all files from the current
> user...
>



 
Reply With Quote
 
Jawloc
Guest
Posts: n/a
 
      02-27-2007
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
zipping files folders and sub folders w/ winzip or winrar Mike Computer Support 5 03-28-2008 09:10 PM
Desktop accesses laptop and reads folders but Laptop only accesses/opens Desktop but cannot read folders, access is denied onclejon Wireless Networking 3 11-01-2006 10:50 PM
NOTE: Storage on small folders, large folders, or one folder Pennywise@DerryMaine.Gov Computer Support 1 06-24-2006 09:09 AM
how to detect file creating and deleting and renaming files immediately in java master007 Java 8 03-06-2006 07:30 PM
Syncing POP folders with IMAP folders Rich Computer Support 1 02-12-2004 09:36 PM



Advertisments