Darrell Hawley: Home Page

Tuesday, April 18, 2006

Shredding a File

I was wondering how to shred a file with C# the other day so I wrote the following lines of code.


System.IO.FileStream stream = new System.IO.FileStream(label1.Text, System.IO.FileMode.Open);
byte[] readbytes = new byte[stream.Length];
long length = stream.Length;
int position = 0;
for (int i = 0; i < readbytes.Length; i++ )
{
readbytes[i] = Randomize();
}
stream.Write(readbytes, position, (int)length);
stream.Close();
System.IO.File.Delete(label1.Text);

I know that the contents of the file will changed before it is deleted, but does the file get written back to the same exact location on disk? The great wiseman, Google, doesn't seem to be of much help on this one.


3 Comments:

Post a Comment

Subscribe to Post Comments [Atom]



<< Home