473,651 Members | 3,011 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

delete directory and file busy

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

i obtain
Exception Details: System.Unauthor izedAccessExcep tion: Access to the
path '***' is denied.

thanks
Nov 8 '07 #1
3 2062
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.Delet e(myPath, true);
2) TextWriter sw = new StreamWriter(my Path +"test.aspx" );

i obtain
Exception Details: System.Unauthor izedAccessExcep tion: Access to the path
'***' is denied.

thanks

Nov 8 '07 #2
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.Delet e(myPath, true);
2) TextWriter sw = new StreamWriter(my Path +"test.aspx" );

i obtain
Exception Details: System.Unauthor izedAccessExcep tion: Access to the
path '***' is denied.

thanks
Nov 9 '07 #3
ok i found !
there are a bug in Directory.Delet e 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.Unauthor izedAccessExcep tion: 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.Delet e(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(p athIn);
foreach (FileSystemInfo fsi in di.GetFileSyste mInfos())
{
if ((fsi.Attribute s & 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.Delet e(myPath, true);
2) TextWriter sw = new StreamWriter(my Path +"test.aspx" );

i obtain
Exception Details: System.Unauthor izedAccessExcep tion: Access to the
path '***' is denied.

thanks
Nov 9 '07 #4

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

Similar topics

44
4031
by: Xah Lee | last post by:
here's a large exercise that uses what we built before. suppose you have tens of thousands of files in various directories. Some of these files are identical, but you don't know which ones are identical with which. Write a program that prints out which file are redundant copies. Here's the spec. -------------------------- The program is to be used on the command line. Its arguments are one or
5
20096
by: betterdie | last post by:
Dear guru I want to delete all file and folder recursivly under php code, can anyone give me commend for this. Thank very much
3
2926
by: News | last post by:
Is it possible to delete a file by copying it to the "bit bucket" or "null device"? Back in my youth when I live in VMS-land you could delete a file by copying it to NL: ========== I have written a windows service as part of an interface between two different systems. The first system will write output into a file in a
12
7989
by: Lucas Tam | last post by:
I have a very simple loop: If (Directory.Exists(tempDirectory)) Then Try Dim Files() As String = Directory.GetFiles(tempDirectory) 'Clear out directory For Each Filename As String In Files File.Delete(Filename) Next Catch ex As Exception
5
3491
by: Sam777 | last post by:
I was under the impression that creating the app_offline.htm file at the root of the webapp would cause all handles to be closed so that the app could be removed. Unfortunately, this isn't the case. One handle remains open. Debugging shows that it's actually the IIS cache and not ASP.NET that owns this handle. During IIS shutdown, the handle is closed with the following stack trace: ChildEBP RetAddr 0006fbe4 5a403e05...
3
3275
by: Arpan | last post by:
A Form has a FileUpload, 2 Buttons & a TextBox web server controls. Using the FileUpload control, I want to give users the provision to move & delete files that DO NOT exist in C:\Inetpub\wwwroot (i.e. the root directory). This is the code: <script runat="server"> Sub MoveFile(ByVal obj As Object, ByVal ea As EventArgs) File.Move(fudFileSource.FileName, txtFileDest.Text) 'File.Move("F:\4.jpg", "C:\4.jpg") End Sub
11
5785
by: comp.lang.php | last post by:
Once again, I thought my class method deleteZip() would do the trick, but it never deletes any .zip* file found in a directory: /** * Delete any latent ZIP files found in this album. This method is to be inherited by all listing classes to allow for * list-wide deletion of latent server-created ZIP files for security purposes *
7
4219
by: Anil Gupte | last post by:
Private Sub mnu2Exit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnu2Exit.Click Dim fDir As String = Path.GetDirectoryName(L3Global.VideoFileName) File.Delete(L3Global.VideoFileName) ' The following is not working - reports directory not empty exception ' Directory.Delete(fDir)
0
2945
by: wolfsbane | last post by:
Alright, here it is I am trying to write a win32 app in VB 2005 to clean up user's profiles. everything works correctly except for the Delete("directory", True) statement. I get a System.IO.DirectoryNotFoundException: Could not find a part of the path. Then it gives me a random file name from the UserProfile\Local Settings\Temporary Internet Files\Content.IE5\SomeRandomFolder. This is absolutley driving me nuts. So I am gonn give you a basic...
0
8361
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
8807
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8701
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
8466
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
8584
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7299
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
5615
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
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4290
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.