Can files deleted by System.IO.File.Delete method be restored?

  • Thread starter Thread starter Raymond Du
  • Start date Start date
R

Raymond Du

Hi,

I am working on a VB.Net window application, the application use
System.IO.File.Delete method to delete files, can those deleted files be
restored?

TIA
 
Raymond Du said:
I am working on a VB.Net window application, the application use
System.IO.File.Delete method to delete files, can those deleted files be
restored?

They cannot be restored using the recycle bin, but the data maybe can be
restored using certain special software.
 
Hi,

You can use the SHFileOperation API delete a file to recycle bin.

The api declare



<DllImport("shell32.dll", entrypoint:="SHFileOperationA", _

setlasterror:=True, CharSet:=CharSet.Auto, exactspelling:=True, _

CallingConvention:=CallingConvention.StdCall)> _

Public Shared Function SHFileOperation(ByRef lpFileOp As SHFILEOPSTRUCT) As
Integer

End Function



The structure



Structure SHFILEOPSTRUCT

Dim hwnd As Integer

Dim wFunc As Integer

Dim pFrom As String

Dim pTo As String

Dim fFlags As Short

Dim fAnyOperationsAborted As Integer

Dim hNameMappings As Integer

Dim lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS

End Structure



The constants



Private Const FO_DELETE = &H3

Private Const FOF_ALLOWUNDO = &H40



And finally the same code.



Dim sh As New SHFILEOPSTRUCT

With sh

.wFunc = FO_DELETE

.pFrom = FileName

.fFlags = FOF_ALLOWUNDO

End With

If SHFileOperation(sh) <> 0 Then

MessageBox.Show("Error deleting file")

End If


Ken

--------------------------

Hi,

I am working on a VB.Net window application, the application use
System.IO.File.Delete method to delete files, can those deleted files be
restored?

TIA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top