Click here to Skip to main content
11,579,898 members (79,682 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hai,

I am creating a directory and files through C#. After creating i want to delete through c#. Its showing error like "Access to the path 'Folder Name' is denied". What is the issue this?

Thanks
Posted 22-Nov-11 23:03pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

When you use File I/O resources you must release them after using.

you can use Process Explorer http://technet.microsoft.com/en-us/sysinternals/bb896653[^]

It has Find handle functionality in Handle menu. Go to find handle and enter file/folder name created with c# and it will find the application which is still aquiring handle of the files.

you can Right Click on the handle in Process explorer lower pane and click close handle to release the handle manually.

finally make sure you are releasing resources such as file streams and disposing the objects for File IO you are using in code to create files/folders before trying to delete them.

Thanks,
hemant

Solution Improved:
Whenever you work with some file operating system assigns a handle and passes it to the application requesting the file. In your case your c# application/Visual Studio is having that handle. Now if any other application will try to delete/Edit the file you will get Access Denied warning. So you must release them. Programatically you should release the File IO objects/streams and to confirm that your c# application is keeping that handle you can use process explorer.

The code you are written is sufficient only but you need to make sure you are releasing resources for example ..
CurrentFileStream = null;
CurrentFileStream.Dispose() etc

If you are still not sure you can post the exact code you are using.
  Permalink  
v3
Comments
Anshumaan Chaturvedi at 12-Jun-14 2:13am
   
Is traversing through this path "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA" possible when the file is having read-only property on. I am actually running the search engine code for searching a file with particular name.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 213
1 Frankie-C 170
2 Abhinav S 65
3 Richard Deeming 60
4 Sergey Alexandrovich Kryukov 49
0 OriginalGriff 1,003
1 Sergey Alexandrovich Kryukov 750
2 Abhinav S 583
3 F-ES Sitecore 420
4 Dave Kreskowiak 419


Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 23 Nov 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100