2

UPDATE 2

Finally testing most of the WindowsAPICodePack interfaces I've found bymyself the way to acces to the deleted Files on the RecycleBin.

The unique problem now is that I need to know how to acces the required property bag to retrieve the deletion date of each file (and folder and link), This is a sample code:

Dim RecycleBin As IKnownFolder = KnownFolders.RecycleBin

For Each File As ShellFile In (From Item As ShellObject In RecycleBin
                               Where Item.GetType = GetType(ShellFile))

    MsgBox(File.Name)
    MsgBox(File.Properties.System.IsDeleted.Value) ' It's empty.
    MsgBox(File.Properties.System.DateAcquired.Value) ' This is not the correct value.
    MsgBox(File.Properties.System.DateArchived.Value) ' This is also not the correct value.
    MsgBox(File.Properties.System.DateCompleted.Value) ' This is also not the correct value.
    MsgBox(File.Properties.System.DateCreated.Value) ' This is also not the correct value.
    MsgBox(File.Properties.System.DateImported.Value) ' This is also not the correct value.

Next File
Prakash Vishwakarma
  • 814
  • 2
  • 9
  • 25
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • possible duplicate of [Accessing the Recycle Bin](http://stackoverflow.com/questions/13208338/accessing-the-recycle-bin) – Kurubaran Jan 06 '14 at 08:32
  • 1
    A question not must be reported as duplicate only if the other question has an marked answer or real solution?... because is not the case and in the other question the guy don't answered a solution about the deletion dates, for me has no sense this kind of reporting in these conditions. – ElektroStudios Jan 06 '14 at 08:38
  • 1
    @ElektroStudios Does it have to be gotten via the `WindowsAPICodePack`? The deleted date and original path is pretty to get. I am just not sure that supports snooping thru the trash - the Recycler is one of those specialized sort of system objects – Ňɏssa Pøngjǣrdenlarp Jan 17 '14 at 17:16
  • @Plutonix, no matter now, I've found the way to call the properties via WindowsAPICodePack, I will post a solution when I can finish the code. but If you know the answer for this: http://stackoverflow.com/questions/21187912/how-to-invoke-a-verb-on-a-shellfile-shellfolder-shellobject-objects-using-window you could post the answer here to gain some points (if you are interested to) – ElektroStudios Jan 17 '14 at 18:20

2 Answers2

2

The Windows API Code Pack might be of some help to you. It has more extensive (full) implementations of most shell interfaces. You will have to open up the code pack items (InternalsVisibleTo application manifest attribute, or just change all the internal interfaces to external) in order to use them away from the given wrappers.

As for the delete date: That's contained in the property bag of the shell item.
The great Raymond Chen, who has been a developer at Microsoft since the beginning of time and personally gave birth to the Windows Shell wrote a complete walk-through article about how to go about doing it in C++, aptly named 'How can I get information about the items in the Recycle Bin?'

You can, with a little bit of logical deduction, take the bits you need away from it and produce your own managed implementation.

Between those two links, you now have all the knowledge in your possession to solve your problem and then some.

Nathan M
  • 873
  • 5
  • 18
  • First of all sorry for commenting late and thankyou for answer. 1. After reading the url documentation 3 times I can't find anything there that can help me (this is because I'm not a `C/C++` programmer, sorry) I only see that it just uses the `IShellFolder` interface to do other things but I can't understand if that can help me. 2. I use the `WindowsAPICodePack` sometimes but for taskbar things, really I don't know how to go inside the recycle bin using the `WindowsAPICodePack` but really I will appreciate a solution using it that could help me. – ElektroStudios Jan 17 '14 at 10:50
  • By the way I've tried to change all the `internal Interface` to `public Interface` in the source (exactly in the `ShellCOMInterfaces.cs` file) but the compiler throws a lot of visibility errors and metadata error in the `windowsapicodepack.Shell.dll` assembly... sorry I don't manage `C#` Then I could need one person that could provide me a new `Windows API Pack` compiled right with those internal changes that you've mentioned, but I know, maybe that is asking for too much... well thanks again. – ElektroStudios Jan 17 '14 at 10:51
  • Finally I've found the way to use WindowsAPICodePack to retrieve the deleted files! but now I need help to retrieve the property bag that you've said, please see my second update, thanks. – ElektroStudios Jan 17 '14 at 11:36
  • You've helped me to investigate deep into WindowsAPICodePack, finally I've done so thanks and answer accepted. – ElektroStudios Jan 17 '14 at 19:01
  • setting InternalsVisibleTo attribute to reference the assembly name (not the namespace) of your project, inside the AssemblyInfo.cs file of the Shell C# library will help you open all of that up very quickly without having to change the scope of the code, itself. It allows all of the internal/friend declares in the shell library become visible to your application. If you are using strong naming, you need to supply the key, too (see: http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute(v=vs.110).aspx ) – Nathan M Jan 19 '14 at 04:42
  • 1
    This article on using the GetDetailsEx function of the IShellFolder2 interface should help you immensely. When you click on the SHCOLUMNID parameter it gives you detailed information for grabbing all kinds of data from the shell. Article: http://msdn.microsoft.com/en-us/library/windows/desktop/bb775051(v=vs.85).aspx – Nathan M Jan 19 '14 at 04:46
1

To retrieve the DateDeleted property of an Item is simple as this:

Private Sub Test() Handles MyBase.Shown

    ' Get all the desired deleted items inside the Recycle Bin using WindowsAPICodePack.
    ' ( In my case I only retrieve the deleted files excluding folders. )
    Dim RecycledFiles As ShellFile() = RecycleBin.MasterBin.Files

    ' Loop through the deleted Items.
    For Each Item As ShellFile In RecycledFiles

        ' Append the full name
        sb.AppendLine(Item.Name)

        ' Append the DateDeleted.
        sb.AppendLine(Item.Properties.GetProperty("DateDeleted").ValueAsObject.ToString)

        MsgBox(sb.ToString)
        sb.Clear()

    Next Item

End Sub

Then to retrieve the last deleted file forexample:

''' <summary>
''' Gets the last deleted file inside recycle bin.
''' </summary>
''' <returns>ShellFile.</returns>
Public Shared Function GetLastDeletedFile() As ShellFile

    Return (From Item As ShellFile In GetDeletedItems(Of ShellFile)(Nothing)
            Order By Item.Properties.GetProperty("DateDeleted").ValueAsObject).Last

End Function

And with this snippet we can retrieve the other property names and values of each:

Dim sb As New System.Text.StringBuilder

Private Sub Test() Handles MyBase.Shown

    ' Get all the desired deleted items inside the Recycle Bin using WindowsAPICodePack.
    ' ( In my case I only retrieve the deleted files excluding folders. )
    Dim RecycledFiles As ShellFile() = RecycleBin.MasterBin.Files

    ' Loop through the deleted Items.
    For Each Item As ShellFile In RecycledFiles

        ' Append the full name (It's String type)
        sb.AppendLine(Item.Name)

        ' Loop through the Item properties.
        For Each prop In Item.Properties.DefaultPropertyCollection

            ' Append an empty line
            sb.AppendLine()

            ' Append the property name (It's String type)
            sb.Append(prop.CanonicalName)

            ' Append the property value (It's a generic Object type)
            If prop.ValueAsObject IsNot Nothing Then
                sb.Append(" = " & prop.ValueAsObject.ToString)
            Else
                sb.Append(" = NULL")
            End If

            MsgBox(sb.ToString)

        Next prop

    Next Item

End Sub

Just another example:

Private Sub Test() Handles MyBase.Shown

    ' Get all the deleted items inside the Recycle Bin using WindowsAPICodePack.
    Dim RecycledItems As ShellObject() = RecycleBin.MainBin.Items

    ' Loop through the deleted Items (Ordered by Deletion Date).
    For Each Item As ShellFile In (From itm In RecycledItems
                                   Order By itm.Properties.GetProperty("DateDeleted").ValueAsObject Ascending)

        ' Append the property bags information.
        sb.AppendLine(String.Format("Full Name: {0}",
                                    Item.Name))

        sb.AppendLine(String.Format("Item Name: {0}",
                                    Item.Properties.GetProperty("System.ItemNameDisplay").ValueAsObject))

        sb.AppendLine(String.Format("Deleted From: {0}",
                                    Item.Properties.GetProperty("DeletedFrom").ValueAsObject))

        sb.AppendLine(String.Format("Item Type: {0}",
                                    Item.Properties.GetProperty("System.ItemTypeText").ValueAsObject))

        sb.AppendLine(String.Format("Item Size: {0}",
                                    Item.Properties.GetProperty("System.Size").ValueAsObject))

        sb.AppendLine(String.Format("Attributes: {0}",
                                    [Enum].Parse(GetType(IO.FileAttributes),
                                                 Item.Properties.GetProperty("System.FileAttributes").ValueAsObject.ToString)))

        sb.AppendLine(String.Format("Date Deleted: {0}",
                                    Item.Properties.GetProperty("DateDeleted").ValueAsObject))

        sb.AppendLine(String.Format("Date Modified: {0}",
                                    Item.Properties.GetProperty("System.DateModified").ValueAsObject))

        sb.AppendLine(String.Format("Date Created: {0}",
                                    Item.Properties.GetProperty("System.DateCreated").ValueAsObject))

        MsgBox(sb.ToString)
        sb.Clear()

    Next Item

End Sub
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • 1
    Note the canonical name for this property is System.Recycle.DateDeleted and it's (vaguely) documented here: http://msdn.microsoft.com/en-us/windows/bb776504.aspx – Simon Mourier Jan 18 '14 at 12:06
  • That's very cool. I started out learning the API in the unmanaged way, back when using C++ was cool, so I know the API the way that C++ spells it out. It is easier for me to hunt the answer down in C++ using the MSDN documentation than to go trudging through the WindowsApiCodePack for silly obvious answers like this one. I didn't even know there was a method to retrieve the properties based on name ... :-) I use the flags and the GUIDs. – Nathan M Jan 19 '14 at 05:00