I was wondering if It is possible to write to freespace in C#? I mean something like FreeSpace.WriteAllBytes() or like what some shredder apps do?
How can I do so?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If your intention is simply to overwrite all the free space available on a hard drive, you can use the
GetDiskFreeSpaceExAPI to determine how many bytes are available and write a file that large (or spread it out among several files).P/Invoke for C#:
You can use a class like System.Random to fill an array of bytes with random values before writing them, if that might interest you.
Edit: Wasn’t aware of the System.IO.DriveInfo class, which could be simpler than using the mentioned API.