list filenames in the recyclebin with c# without using any external files

风格不统一 提交于 2019-11-30 23:08:53

If you add a reference C:\Windows\System32\Shell32.dll to in your application you can easily access the filenames of the files in the Recyle Bin

Example:

    using Shell32;

    public IEnumerable<string> GetRecycleBinFilenames()
    {
        Shell shell = new Shell();
        Folder recycleBin = shell.NameSpace(10);

        foreach (FolderItem2 recfile in recycleBin.Items())
        {
            // Filename
            yield return recfile.Name;

            // full recyclepath
            // yield return recfile.Path;
        }

        Marshal.FinalReleaseComObject(shell);
    }

If the extra file created bothers you you can embed it in the executable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!