We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

File Deletion

Last post 05-08-2008 12:33 PM by moizmala. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 05-06-2008 6:45 AM

    File Deletion

    Hi, 

    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)

    {

    System.IO.File.Delete(fileName);

    }

     

    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,

    Murali

    • Post Points: 10
  • 05-08-2008 12:33 PM In reply to

    • moizmala
    • Not Ranked
    • Joined on 05-08-2008
    • India
    • New Member
    • Points 15

    Re: File Deletion

    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.

    Regards,

    Moiz

    • Post Points: 5
Page 1 of 1 (2 items)