Share via

How to let VirtualFileDataObject include empty folders

Mad Tom 5 Reputation points
2026-05-12T09:38:18.7466667+00:00

Hi, I’m creating a WPF app to drag virtual files out to explorer, using source code from

https://dlaa.me/blog/post/9923072

 

I need my drag-out files to include some empty folders, but how can I do that.

 

Or can I detect the target path where I drop these files to.

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Mad Tom 5 Reputation points
    2026-05-12T10:25:48.9633333+00:00

    Okay, after a little research, now I get it done:

    1.      Add FD_ATTRIBUTES=0x00000004 to [NativeMethods] value table;

    See [MS-RDPECLIP]: File Descriptor (CLIPRDR_FILEDESCRIPTOR) | Microsoft Learn

    2.      Add a property to FileDescriptor class:

        public bool IsDirectory { get; set; } = false;
    

    3.      Edit test code where new FileDescriptor,

        set IsDirectory = true;
    

    4.      Add code to SetData{IEnumerable<FileDescriptor> fileDescriptors} method:

           if (fileDescriptor.IsDirectory)

           {

                FILEDESCRIPTOR.dwFlags |= NativeMethods.FD_ATTRIBUTES;

                FILEDESCRIPTOR.dwFileAttributes = 0x00000010; // value of FILE_ATTRIBUTE_DIRECTORY

           }

    5.      Build and test run, working! Very nice. ;D

    Was this answer helpful?

    1 person found this answer helpful.

  2. AI answer

    2026-05-12T09:38:32.7866667+00:00

    Virtual folders and virtual drag-out data are described in the Shell as arbitrary objects that are exposed through IDataObject rather than as real file system items. Empty folders are just another kind of object that the data object must describe.

    To include empty folders when dragging virtual content out to Explorer, the data object must advertise them in the Shell formats used for non-file-system items, not only in CF_HDROP:

    1. Use CFSTR_FILEDESCRIPTOR/CFSTR_FILECONTENTS instead of only CF_HDROP.
      • For virtual items, the Shell documentation states that data is normally transferred using the CFSTR_FILEDESCRIPTOR/CFSTR_FILECONTENTS formats, not CF_HDROP.
      • Each entry in the FILEDESCRIPTOR array describes one object (file or folder). For a folder, set the appropriate attributes (directory flag) and omit CFSTR_FILECONTENTS (because there is no file data to stream).
      • Explorer will then create the folder structure on drop, even for empty folders, based solely on the descriptors.
    2. Ensure the virtual folder implementation exposes an IDataObject that includes descriptors for folder items.
      • When Explorer requests an IDataObject for the selected items (via IShellFolder::GetUIObjectOf in a namespace extension, or equivalent logic in a custom helper like VirtualFileDataObject), the implementation must:
        • Add a FILEDESCRIPTOR entry for each folder.
        • Mark those entries as directories.
        • Provide CFSTR_FILECONTENTS only for items that have streamable content (files), not for empty folders.
    3. Detecting the target path of the drop is not supported from the drag source side.
      • In the Shell drag-and-drop model, the drag source provides data through IDataObject; the drop target (Explorer) decides where to materialize that data.
      • The source does not get a callback with the final file-system path. The Shell documentation for namespace extensions and data transfer focuses on providing IDataObject/IDropTarget implementations, not on exposing the destination path back to the source.
      • Therefore, the correct approach is to describe the full virtual hierarchy (including empty folders) in the data object and let Explorer create it at the user-chosen destination.

    In a WPF app, this means constructing a DataObject that carries the Shell formats (CFSTR_FILEDESCRIPTOR/CFSTR_FILECONTENTS) describing both files and folders, then passing it to DragDrop.DoDragDrop. Explorer will then create the corresponding folder tree, including empty folders, at the drop location, but that location is not reported back to the app.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.