Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
file or directory is corrupted and unreadable in c# using windows application
Posted
Comments
ZurdoDev 12-Mar-12 8:05am    
Are you trying to ask a question?

As the general solution, this behavior can occur if the file, folder or file system index (Master File Table [MFT] or File Allocation Table [FAT]) is damaged.

As an attempt to repair the damaged file, folder or file system index using Chkdsk. To do so, follow these steps
1. Click Start, and then click Run.
2. In the Open box, type chkdsk /f <drive>:, where <drive> is the letter of the drive on which the damaged file, folder or file system index exists.
3. Click OK.
 
Share this answer
 
As the solution against file write operation, write caching doesn't cause file corruption. Shutting the machine off while the file is open causes the file corruption.

If you capture the exception then you should be able to delete the file.

You can probably lessen the frequency of errors if you call Flush on the log file whenever you write to it. You can almost completely eliminate the error if you close the file after every write (which, of course, would require that you open it for append before every write). That might be prohibitively expensive.

You can't completely eliminate the error as long as the only way to shut down the application is to remove power. You might consider rotating the log, though, so if it does get corrupted you only lose the last hour or so.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900