locked
VB .NET File Shredder????

    Question

  •  

    Is there a way to make a file shredder in VB .NET, I don't mean just deleting the file the normal "windows way" but to actually overwrite the contents of a file on the drive via diffrent methods such as the DoD method,  just to name one.  Perhaps this can be done by use of a library?
    Wednesday, September 05, 2007 2:25 AM

Answers

  • RyanB88,

     

    Based on your post, you would like to make a file shredder application in VB.NET. I would like to provide you the following suggestions:

     

    1. Overwrite the contents of a file on the drive issue: On .NET Framework, you can use My.Computer.FileSystem.WriteAllText method to write to the specific file:

     

    My.Computer.FileSystem.WriteAllText("C:\test.log", "This is a test", True)

    The first parameter is the filename, the second is the string, and the third is append = true and overwrite = false.

     

    To write it multiple times, you could use a for loop.. ie

     

    For i As Integer = 1 To 100  'write string 100 times

    My.Computer.FileSystem.WriteAllText("C:\test.log", "This is a test", True)

    Next

    MsgBox("Done")

     

    For further information on the issue, please take a look at the following thread:

     

    How to overwrite file contents from a file to an other

     

    2. File Shredder application: Actually there are some problems to build this kind of application on .NET Framework. For example, on NTFS volumn, you may not be able to delete a file if the file uses an Access Control List (ACL). To resolve this issue, change the permissions on the file. You may have to take ownership of the files to be able to change the permissions.

    The following article shows the detailed information on different situation:

     

    You cannot delete a file or a folder on an NTFS file system volume

     

    There are many related applications on Internet. You can also download one of the file shredder applications to have a try.

    Hope that can provide you some idea.
    Friday, September 07, 2007 6:46 AM

All replies

  • RyanB88,

     

    Based on your post, you would like to make a file shredder application in VB.NET. I would like to provide you the following suggestions:

     

    1. Overwrite the contents of a file on the drive issue: On .NET Framework, you can use My.Computer.FileSystem.WriteAllText method to write to the specific file:

     

    My.Computer.FileSystem.WriteAllText("C:\test.log", "This is a test", True)

    The first parameter is the filename, the second is the string, and the third is append = true and overwrite = false.

     

    To write it multiple times, you could use a for loop.. ie

     

    For i As Integer = 1 To 100  'write string 100 times

    My.Computer.FileSystem.WriteAllText("C:\test.log", "This is a test", True)

    Next

    MsgBox("Done")

     

    For further information on the issue, please take a look at the following thread:

     

    How to overwrite file contents from a file to an other

     

    2. File Shredder application: Actually there are some problems to build this kind of application on .NET Framework. For example, on NTFS volumn, you may not be able to delete a file if the file uses an Access Control List (ACL). To resolve this issue, change the permissions on the file. You may have to take ownership of the files to be able to change the permissions.

    The following article shows the detailed information on different situation:

     

    You cannot delete a file or a folder on an NTFS file system volume

     

    There are many related applications on Internet. You can also download one of the file shredder applications to have a try.

    Hope that can provide you some idea.
    Friday, September 07, 2007 6:46 AM
  •  Bruno Yu - MSFT wrote:

    RyanB88,

     

    Based on your post, you would like to make a file shredder application in VB.NET. I would like to provide you the following suggestions:

     

    1. Overwrite the contents of a file on the drive issue: On .NET Framework, you can use My.Computer.FileSystem.WriteAllText method to write to the specific file:

     

    My.Computer.FileSystem.WriteAllText("C:\test.log", "This is a test", True)

    The first parameter is the filename, the second is the string, and the third is append = true and overwrite = false.

     

    To write it multiple times, you could use a for loop.. ie

     

    For i As Integer = 1 To 100  'write string 100 times

    My.Computer.FileSystem.WriteAllText("C:\test.log", "This is a test", True)

    Next

    MsgBox("Done")

     

    For further information on the issue, please take a look at the following thread:

     

    How to overwrite file contents from a file to an other

     

    2. File Shredder application: Actually there are some problems to build this kind of application on .NET Framework. For example, on NTFS volumn, you may not be able to delete a file if the file uses an Access Control List (ACL). To resolve this issue, change the permissions on the file. You may have to take ownership of the files to be able to change the permissions.

    The following article shows the detailed information on different situation:

     

    You cannot delete a file or a folder on an NTFS file system volume

     

    There are many related applications on Internet. You can also download one of the file shredder applications to have a try.

    Hope that can provide you some idea.

     

    verry helpful indeed.  Thank you, now I have to search for the details on the diffrent standards for data removal such as the DoD standard in hopes of seeing is I could impliment them with my app.

    Saturday, September 08, 2007 12:28 PM
  • I don't think this is possible in managed code. The issue is that when you're using .NET functions you're interacting with the abstracted file at a very high level, through the entire file system stack... Therefore, when you open the file and write your garbage into it, there's no real telling just how clever the OS is going to get about fulfilling your request, and therefore no guarantee that the bits you write X thousands of times are actually going on top of the ones you're trying to erase.

    It could decide, for instance, that the existing file is too fragmented on disk, and when you write anything more to it it puts the new bits at the beginning of your free space. I don't know that it actually DOES do any such thing, but there's no guarantee it DOESN'T either. As well, it could do so on one version of windows and not do so on another (or even the same version with and without some given hotfix.) It might well work sometimes, but it would achieve an almost quantum level of unreliability.

    You'll have to invoke Unsafe/Native code to ensure shredding, which means the answer you're looking for lies more with C/C++ and Win32 than the VB forums.
    Friday, September 14, 2007 9:42 PM