By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,454 Members | 3,103 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,454 IT Pros & Developers. It's quick & easy.

delete directory and file busy

P: n/a
hello, i ve a probleme when deleting a directory and when i want create
file immediatly after.
1) Directory.Delete(myPath, true);
2) TextWriter sw = new StreamWriter(myPath +"test.aspx");

i obtain
Exception Details: System.UnauthorizedAccessException: Access to the
path '***' is denied.

thanks
Nov 8 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Have you seen you try to create a file in a directory you just deleted ? I
would just fix this programming error (not sure if the question is why this
happens or if you are unhappy with the exception that is raised and that you
would like have another one)...

--
Patrice

"Steph" <st***@pipoland.coma écrit dans le message de news:
47**********************@news.orange.fr...
hello, i ve a probleme when deleting a directory and when i want create
file immediatly after.
1) Directory.Delete(myPath, true);
2) TextWriter sw = new StreamWriter(myPath +"test.aspx");

i obtain
Exception Details: System.UnauthorizedAccessException: Access to the path
'***' is denied.

thanks

Nov 8 '07 #2

P: n/a
have you tried to give full control access to your app?

u may try to give full control( read , write, modify ) access to
EVERYONE.

right click the folder on your server -share and security -...

may it help, thanks

Ryan Gene

Steph wrote:
hello, i ve a probleme when deleting a directory and when i want create
file immediatly after.
1) Directory.Delete(myPath, true);
2) TextWriter sw = new StreamWriter(myPath +"test.aspx");

i obtain
Exception Details: System.UnauthorizedAccessException: Access to the
path '***' is denied.

thanks
Nov 9 '07 #3

P: n/a
ok i found !
there are a bug in Directory.Delete if you use recursive mode.
when you delete a directory recursively, re create it, and reinstall the
new file, you obtain this error :
Exception Details: System.UnauthorizedAccessException: Access to the
>path '***' is denied.
But, if you create your own function to delete recursively the
directory, re create it, and reinstall the new file, all is fine.

Conclusion :
dont use : Directory.Delete(xxx,true);
but :

/// <summary>
/// DirectoryDelete v1.0 by EL - 07/09/11
/// </summary>
/// <param name="pathIn"></param>
public void DirectoryDelete(string pathIn)
{
DirectoryInfo di = new DirectoryInfo(pathIn);
foreach (FileSystemInfo fsi in di.GetFileSystemInfos())
{
if ((fsi.Attributes & FileAttributes.Directory) != 0)
{
DirectoryDelete(fsi.FullName);
fsi.Delete();
}
else
{
fsi.Delete();
}
fsi.Refresh();
}
}

Ji*******@gmail.com wrote:
have you tried to give full control access to your app?

u may try to give full control( read , write, modify ) access to
EVERYONE.

right click the folder on your server -share and security -...

may it help, thanks

Ryan Gene

Steph wrote:
>hello, i ve a probleme when deleting a directory and when i want create
file immediatly after.
1) Directory.Delete(myPath, true);
2) TextWriter sw = new StreamWriter(myPath +"test.aspx");

i obtain
Exception Details: System.UnauthorizedAccessException: Access to the
path '***' is denied.

thanks
Nov 9 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.