A: 

Not understanding what you want to do so much, but what about chmoding it to 777 or 775. :-/

Edit:

Noticed your on windows. You'd have to change the permissions. Don't know how windows does that :-/

EpicDewd
A: 

What OS are you running ? Windows 7 ?

piet
A: 

First of all: "Crash" means an exception, right? Which one? Can you catch it and show it?

Second thing: You are copying subversion repositories, although you don't care about the subversion metadata? That's what svn export is about (no .svn directory in the target).

The answer to the first question is what you really need to provide. Maybe something grabs the .svn and locks some files. TortoiseSVN maybe (to give you nice overlay icons..)?

Benjamin Podszun
+2  A: 

The only problem I see would be in this part:

// ... do some stuff to the cache to verify what I need.

If you do open the file and forget to close it, you still have exclusive access to it, and thus can't delete it later on.

Femaref
Agreed. If you're dealing with `FileStream` objects, be sure to call `Close` on them (which calls `Dispose`). Even better would be to simply wrap them in `using` blocks.
Dan Tao
This wont be the cause - if you do that then you prevent other processes from deleting the file, however if the same process attempts to delete the file then there is no problem, as the handle / lock is owned by the same process. I've tested this and it does not cause an exception.
Kragen
+1  A: 

Sounds like you don't have access to delete the file...

system.io.file.delete

The above link says you get UnauthorizedAccessException when:

The caller does not have the required permission.

-or-

path is a directory.

-or-

path specified a read-only file.

It's one of those.

Matt Ellen
He must have access to delete the file as he had access to create the file in the first place.
Kragen
Well, he said himself it's the exception that's being throw, I don't know how.
Matt Ellen
A: 

Your asp process clearly has write access to the directory, have you checked that it also has delete access?

runrunraygun
+1  A: 

Sounds like a permissions issue. Tricky one though as you obviously have write access if the File.Copy already works....

Only thing I could think of is the file still has a handle opened somewhere (as others have suggested perhaps in your do some stuff to the cache part).

James
He must have access to delete the file as he had access to create the file in the first place.
Kragen
@Kragen I actually already stated that in my response...
James
+5  A: 

As far as I recall, Subversion marks the files in its .svn subdirectories as read-only.

Try resetting the read-only attribute before deleting the file. I don't really know any C#, but a quick Google suggests this might do the trick:

File.SetAttributes(file, FileAttributes.Normal);
Martin B
I've tested this out, and of all the suggestions so far this is the only one that actually caused an exception!
Kragen
Good call! I hadn't considered "Read Only." However, it still throws the exception.I'm really about to bash something, here. =)
Jerry
GOT IT!! Finally... the second crash was due to another oddity, not this issue.
Jerry