VB.Net RecycleBin is not declared

82 views Asked by At

I refer to this post How to retrieve the 'Deletion Date' property of an Item stored in the Recycle Bin using Windows API Code Pack?

I refer to the answer by @ElektroStudios. I am trying to run that code. My knowledge of VB.net is very little.

Imports Microsoft.WindowsAPICodePack.Shell
Imports System.Text

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim RecycledFiles As ShellFile() = RecycleBin.MasterBin.Files


        Dim sb As StringBuilder
        ' 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
End Class

However, I get a compiler error that RecycleBin is not declared. at

RecycleBin.MasterBin.Files

I am not too sure how to make this work. What is it that I am missing here? Is that a correct code ? Am I missing any Imports or any references?

I have already installed

nuget\Install-Package WindowsAPICodePack-Core

nuget\Install-Package WindowsAPICodePack-Shell

Note - I have already succeeded in accessing the RecycleBin using

SH.NameSpace(Shell32.ShellSpecialFolderConstants.ssfBITBUCKET) 

I am specifically interested in that above piece of code. Thanks

1

There are 1 answers

2
Simon Mourier On

To get the deletion date for items in the Recycle Bin, you don't need any extra libraries, you can use the Shell Objects for Scripting and Microsoft Visual Basic library (which I understand you already found in your last sentences) and the ExtendedProperty method.

Here is some code that dumps items in the recycle bin and their deletion date:

Sub Main()

    Dim shell = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"))
    Const ssfBITBUCKET As Integer = 10
    Dim folder = shell.Namespace(ssfBITBUCKET)

    For Each item In folder.Items
        ' dump some standard properties
        Console.WriteLine(item.Path)
        Console.WriteLine(item.ModifyDate)

        ' dump extended properties (note they are typed, here as a Date)
        Dim dd As Date = item.ExtendedProperty("DateDeleted")
        Console.WriteLine(dd)

        ' same but using the "canonical name"
        ' see https://learn.microsoft.com/en-us/windows/win32/api/propsys/nf-propsys-psgetpropertydescriptionbyname#remarks
        Console.WriteLine(item.ExtendedProperty("System.Recycle.DateDeleted"))
    Next

End Sub