Click here to Skip to main content
16,007,885 members
Home / Discussions / C#
   

C#

 
Generalstring value in url Pin
eyeseetee3-Jan-08 4:13
eyeseetee3-Jan-08 4:13 
GeneralRe: string value in url Pin
Not Active3-Jan-08 4:50
mentorNot Active3-Jan-08 4:50 
QuestionAdding a RichTextBox to a Tab Page Pin
Programm3r3-Jan-08 4:07
Programm3r3-Jan-08 4:07 
AnswerRe: Adding a RichTextBox to a Tab Page Pin
Programm3r3-Jan-08 4:12
Programm3r3-Jan-08 4:12 
GeneralRe: Adding a RichTextBox to a Tab Page Pin
Justin Perez3-Jan-08 4:14
Justin Perez3-Jan-08 4:14 
GeneralRe: Adding a RichTextBox to a Tab Page Pin
Programm3r3-Jan-08 4:44
Programm3r3-Jan-08 4:44 
GeneralRe: Adding a RichTextBox to a Tab Page Pin
Justin Perez3-Jan-08 5:02
Justin Perez3-Jan-08 5:02 
GeneralCompletely delete a file Pin
Johan Martensson3-Jan-08 2:51
Johan Martensson3-Jan-08 2:51 
Hello all, I got a new question for you today Smile | :)

I've been playing around with the concept of wiping files from a thumbdrive and it seems to be working pretty well.

I have the code below and the file seems to be overwritten as they should.
I have tested Ontrack EasyRecovery and PC Inspector File Recovery and I wasn't able to get any viewable data back.

The only annoying thing is that booth recovery-applications were able to bring back the filename of the overwritten file which I don't want of course.

If I don't rename the file before overwriting it, all that is recovered is a zero-byte file with the correct filename.
If I rename it first, I can recover a file with the correct filename and size but the data is destroyed.

So what I'm asking for is, is there a way to completely delete a file or change the name of the file permanently so it can't be recovered.

private void WipeFile(string filename, int timesToWrite)
{
    if(File.Exists(filename))
    {
        // Rename the file
        string newFileName = Path.GetDirectoryName(filename) + GetRandomFileName();
        File.Move(filename, newFileName);
        filename = newFileName;
         
        // Create a buffer for the dummy-data
        byte[] dummyBuffer = new byte[new FileInfo(filename).Length];
        RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
        // Fill the buffer with random data
        rng.GetBytes(dummyBuffer);
                
        // Write to the file n times
        for (int timesWritten = 0; timesWritten < timesToWrite; timesWritten++)
        {
            FileStream inputStream = new FileStream(filename, FileMode.Create);
            inputStream.Write(dummyBuffer, 0, dummyBuffer.Length);
            // Get some new dummy-data
            rng.GetBytes(dummyBuffer);
            inputStream.Close();
        }

        // Create a zero-byte file
        FileStream tmpStream = new FileStream(filename, FileMode.Create);
        tmpStream.Close();

        File.Delete(filename);
    }
}


http://johanmartensson.se - Home of MPEG4Watcher

GeneralRe: Completely delete a file Pin
Paul Conrad3-Jan-08 7:29
professionalPaul Conrad3-Jan-08 7:29 
GeneralRe: Completely delete a file Pin
Johan Martensson3-Jan-08 13:59
Johan Martensson3-Jan-08 13:59 
GeneralRe: Completely delete a file Pin
PIEBALDconsult3-Jan-08 8:55
mvePIEBALDconsult3-Jan-08 8:55 
GeneralRe: Completely delete a file Pin
PIEBALDconsult3-Jan-08 16:18
mvePIEBALDconsult3-Jan-08 16:18 
GeneralRe: Completely delete a file Pin
Johan Martensson3-Jan-08 23:29
Johan Martensson3-Jan-08 23:29 
GeneralRe: Completely delete a file [modified] Pin
PIEBALDconsult4-Jan-08 5:51
mvePIEBALDconsult4-Jan-08 5:51 
GeneralRe: Completely delete a file Pin
Johan Martensson4-Jan-08 7:09
Johan Martensson4-Jan-08 7:09 
GeneralRe: Completely delete a file Pin
PIEBALDconsult4-Jan-08 10:03
mvePIEBALDconsult4-Jan-08 10:03 
GeneralRe: Completely delete a file [modified] Pin
Johan Martensson4-Jan-08 12:27
Johan Martensson4-Jan-08 12:27 
GeneralRe: Completely delete a file Pin
PIEBALDconsult4-Jan-08 16:13
mvePIEBALDconsult4-Jan-08 16:13 
GeneralRe: Completely delete a file Pin
Johan Martensson4-Jan-08 21:48
Johan Martensson4-Jan-08 21:48 
GeneralRe: Completely delete a file Pin
PIEBALDconsult5-Jan-08 4:47
mvePIEBALDconsult5-Jan-08 4:47 
GeneralRe: Completely delete a file Pin
Johan Martensson6-Jan-08 11:51
Johan Martensson6-Jan-08 11:51 
GeneralRe: Completely delete a file Pin
PIEBALDconsult6-Jan-08 13:45
mvePIEBALDconsult6-Jan-08 13:45 
GeneralRe: Completely delete a file Pin
Johan Martensson7-Jan-08 1:12
Johan Martensson7-Jan-08 1:12 
GeneralCalling InitializeFromBitmap fails with exception "The method or operation is not implemented" Pin
KeesVer3-Jan-08 2:29
KeesVer3-Jan-08 2:29 
GeneralRe: Calling InitializeFromBitmap fails with exception "The method or operation is not implemented" Pin
KaptinKrunch3-Jan-08 16:29
KaptinKrunch3-Jan-08 16:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.