File Deletion

  • 12 years ago


    I tried to delete an exiting file from the application using C#. The statement is as follows:

    bool fileExists = System.IO.File.Exists(fileName);

    if (fileExists == true)





    But i"m getting the exception like:

    The process cannot access the file because it is being used by another process.

    Can anyone give the solution to access the file and delete without any exceptions.


    Thanks in advance,


  • 12 years ago

    Hi Murali,

     It will be better u use StreamReader IO objects and access the file. You write a code to open ur file in Share Mode which has to be deleted by the reader object and then close the file. Then you delete it. This will have acess control on that file to delete. And make sure the file you are deleting has proper permission set.



Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves” - Alan Kay