Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
If i want to delete a file A
So the pointer to this file will be deleted only
and its content will still on hard

if i want to overwrite this content so the user will not be able to restore this file content by using writing from another file content B on deleted file A Content
what will be the suitable procedure for me in C#

What I have tried:

Copyfile to fill all available hard storage and overwrite deleted files
but i think it is wrong
Posted
Updated 13-Dec-16 23:57pm
v2

To do it programmatically, I am afraid you have to go very low level. If you are allowed to use a tool then your job would be easier, see, for instance: 5 Tools To Permanently Delete Sensitive Data From Your Hard Drive [Windows][^].
 
Share this answer
 
You can try to open the file for overwriting and write file size random or fixed bytes before deleting it.

But if this will overwrite the same physical sectors on the disk depends on the file system. While this should work for FAT, it might not work for NTFS. It is an interesting question which I did not get answered by a (rather short) web research.

If the file size is very small (less than a KB), it should work for NTFS too because the first data bytes are stored in the MFT which location on the disk is probably not changed (creating a new MFT instead of reusing the existing one would be less performant). This would also ensure that at least the first bytes of larger files are not recoverable.
 
Share this answer
 
Comments
oula alsheikh 14-Dec-16 16:24pm    
you mentioned that when we overwrite a file content by new data
,new data will not be written on original data sectors in NTFS
So NTFS remarked the old data as deleted and creates new data as a new file
so overwriting a file with n bytes will need 2n or maybe more bytes for old and new data
have any links please

assuming that we are going to write on a file then deleting it
what about streamwriter method does it work by same mechanism
and is it specific for text files or it can handle any other types of files
Jochen Arndt 14-Dec-16 16:42pm    
I wrote "it might not work for NTFS".
That means I did not know it for sure.

NTFS uses MFT's for files and directories. These should not be located on a new sector when overwritng an existing file (again: should = not for sure, but very probable in this case). A short description can be found at http://ntfs.com/ntfs-mft.htm-

Don't care about high level methods. It all depends on the file system. I have no links but told you that it is an interesting topic which requires some research.

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