A test adapted from the code I had posted (I removed the Button (in comments) and simplified a bit..)
I set the WPD folder as selected folder on opening, and the selected files are copied to the Documents folder =>
public partial class Form1 : Form
{
public enum HRESULT : uint
{
S_OK = 0,
S_FALSE = 1,
E_NOINTERFACE = 0x80004002,
E_NOTIMPL = 0x80004001,
E_FAIL = 0x80004005,
E_INVALIDARG = 0x80070057,
E_CANCELLED = 0x80070000 + ERROR_CANCELLED,
E_UNEXPECTED = 0x8000FFFF
}
public const uint ERROR_CANCELLED = 1223;
[ComImport]
[System.Runtime.InteropServices.Guid("947aab5f-0a5c-4c13-b4d6-4bf7836fc9f8")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IFileOperation
{
//uint Advise(IFileOperationProgressSink pfops);
HRESULT Advise(IntPtr pfops, ref uint pdwCookie);
HRESULT Unadvise(uint dwCookie);
HRESULT SetOperationFlags(FILEOP_FLAGS dwOperationFlags);
HRESULT SetProgressMessage([MarshalAs(UnmanagedType.LPWStr)] string pszMessage);
HRESULT SetProgressDialog([MarshalAs(UnmanagedType.Interface)] object popd);
HRESULT SetProperties([MarshalAs(UnmanagedType.Interface)] object pproparray);
HRESULT SetOwnerWindow(uint hwndParent);
HRESULT ApplyPropertiesToItem(FileDialog.IShellItem psiItem);
HRESULT ApplyPropertiesToItems([MarshalAs(UnmanagedType.Interface)] object punkItems);
HRESULT RenameItem(FileDialog.IShellItem psiItem, [MarshalAs(UnmanagedType.LPWStr)] string pszNewName,
//IFileOperationProgressSink pfopsItem);
IntPtr pfopsItem);
HRESULT RenameItems([MarshalAs(UnmanagedType.Interface)] object pUnkItems, [MarshalAs(UnmanagedType.LPWStr)] string pszNewName);
HRESULT MoveItem(FileDialog.IShellItem psiItem, FileDialog.IShellItem psiDestinationFolder, [MarshalAs(UnmanagedType.LPWStr)] string pszNewName,
//IFileOperationProgressSink pfopsItem);
IntPtr pfopsItem);
HRESULT MoveItems([MarshalAs(UnmanagedType.Interface)] object punkItems, FileDialog.IShellItem psiDestinationFolder);
HRESULT CopyItem(FileDialog.IShellItem psiItem, FileDialog.IShellItem psiDestinationFolder, [MarshalAs(UnmanagedType.LPWStr)] string pszCopyName,
//IFileOperationProgressSink pfopsItem);
IntPtr pfopsItem);
HRESULT CopyItems([MarshalAs(UnmanagedType.Interface)] object punkItems, FileDialog.IShellItem psiDestinationFolder);
HRESULT DeleteItem(FileDialog.IShellItem psiItem,
//IFileOperationProgressSink pfopsItem);
IntPtr pfopsItem);
HRESULT DeleteItems([MarshalAs(UnmanagedType.Interface)] object punkItems);
HRESULT NewItem(FileDialog.IShellItem psiDestinationFolder, System.IO.FileAttributes dwFileAttributes, [MarshalAs(UnmanagedType.LPWStr)] string pszName,
[MarshalAs(UnmanagedType.LPWStr)] string pszTemplateName,
//IFileOperationProgressSink pfopsItem);
IntPtr pfopsItem);
HRESULT PerformOperations();
[return: MarshalAs(UnmanagedType.Bool)]
bool GetAnyOperationsAborted();
}
[Flags]
public enum FILEOP_FLAGS : uint
{
FOF_MULTIDESTFILES = 0x0001,
FOF_CONFIRMMOUSE = 0x0002,
FOF_SILENT = 0x0004, // don't create progress/report
FOF_RENAMEONCOLLISION = 0x0008,
FOF_NOCONFIRMATION = 0x0010, // Don't prompt the user.
FOF_WANTMAPPINGHANDLE = 0x0020, // Fill in SHFILEOPSTRUCT.hNameMappings
// Must be freed using SHFreeNameMappings
FOF_ALLOWUNDO = 0x0040,
FOF_FILESONLY = 0x0080, // on *.*, do only files
FOF_SIMPLEPROGRESS = 0x0100, // means don't show names of files
FOF_NOCONFIRMMKDIR = 0x0200, // don't confirm making any needed dirs
FOF_NOERRORUI = 0x0400, // don't put up error UI
FOF_NOCOPYSECURITYATTRIBS = 0x0800, // dont copy NT file Security Attributes
FOF_NORECURSION = 0x1000, // don't recurse into directories.
FOF_NO_CONNECTED_ELEMENTS = 0x2000, // don't operate on connected file elements.
FOF_WANTNUKEWARNING = 0x4000, // during delete operation, warn if nuking instead of recycling (partially overrides FOF_NOCONFIRMATION)
FOF_NORECURSEREPARSE = 0x8000, // treat reparse points as objects, not containers
FOFX_NOSKIPJUNCTIONS = 0x00010000, // Don't avoid binding to junctions (like Task folder, Recycle-Bin)
FOFX_PREFERHARDLINK = 0x00020000, // Create hard link if possible
FOFX_SHOWELEVATIONPROMPT = 0x00040000, // Show elevation prompts when error UI is disabled (use with FOF_NOERRORUI)
FOFX_EARLYFAILURE = 0x00100000, // Fail operation as soon as a single error occurs rather than trying to process other items (applies only when using FOF_NOERRORUI)
FOFX_PRESERVEFILEEXTENSIONS = 0x00200000, // Rename collisions preserve file extns (use with FOF_RENAMEONCOLLISION)
FOFX_KEEPNEWERFILE = 0x00400000, // Keep newer file on naming conflicts
FOFX_NOCOPYHOOKS = 0x00800000, // Don't use copy hooks
FOFX_NOMINIMIZEBOX = 0x01000000, // Don't allow minimizing the progress dialog
FOFX_MOVEACLSACROSSVOLUMES = 0x02000000, // Copy security information when performing a cross-volume move operation
FOFX_DONTDISPLAYSOURCEPATH = 0x04000000, // Don't display the path of source file in progress dialog
FOFX_DONTDISPLAYDESTPATH = 0x08000000, // Don't display the path of destination file in progress dialog
}
[DllImport("Shell32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern HRESULT SHCreateItemFromParsingName(string pszPath, IntPtr pbc, ref Guid riid, ref IntPtr ppv);
[DllImport("Shell32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern HRESULT SHGetKnownFolderItem(ref Guid rfid, KNOWN_FOLDER_FLAG flags, IntPtr hToken, ref Guid riid, ref IntPtr ppv);
public enum KNOWN_FOLDER_FLAG: uint
{
KF_FLAG_DEFAULT = 0x00000000,
KF_FLAG_FORCE_APP_DATA_REDIRECTION = 0x00080000,
KF_FLAG_RETURN_FILTER_REDIRECTION_TARGET = 0x00040000,
KF_FLAG_FORCE_PACKAGE_REDIRECTION = 0x00020000,
KF_FLAG_NO_PACKAGE_REDIRECTION = 0x00010000,
KF_FLAG_FORCE_APPCONTAINER_REDIRECTION = 0x00020000,
KF_FLAG_NO_APPCONTAINER_REDIRECTION = 0x00010000,
KF_FLAG_CREATE = 0x00008000,
KF_FLAG_DONT_VERIFY = 0x00004000,
KF_FLAG_DONT_UNEXPAND = 0x00002000,
KF_FLAG_NO_ALIAS = 0x00001000,
KF_FLAG_INIT = 0x00000800,
KF_FLAG_DEFAULT_PATH = 0x00000400,
KF_FLAG_NOT_PARENT_RELATIVE = 0x00000200,
KF_FLAG_SIMPLE_IDLIST = 0x00000100,
KF_FLAG_ALIAS_ONLY = 0x80000000,
}
public Form1()
{
InitializeComponent();
}
private System.Windows.Forms.Button button1;
private System.Windows.Forms.ListBox listBox1;
private void Form1_Load(object sender, EventArgs e)
{
button1 = new Button();
listBox1 = new ListBox();
button1.Location = new System.Drawing.Point(190, 24);
button1.Name = "Button1";
button1.Size = new System.Drawing.Size(75, 23);
button1.TabIndex = 0;
button1.Text = "Choose Files";
button1.UseVisualStyleBackColor = true;
button1.Click += new System.EventHandler(button1_Click);
listBox1.FormattingEnabled = true;
listBox1.Location = new System.Drawing.Point(10, 77);
listBox1.Name = "ListBox1";
listBox1.Size = new System.Drawing.Size(460, 174);
listBox1.TabIndex = 1;
this.Controls.Add(this.listBox1);
this.Controls.Add(this.button1);
this.ClientSize = new System.Drawing.Size(480, 261);
this.Text = "Test IFileDialog and copy items to Documents folder";
CenterToScreen();
}
private void button1_Click(object sender, EventArgs e)
{
FileDialog fileDialog;
//string sFolder = "E:\\temp";
// WPD
string sFolder = "shell:::{35786D3C-B075-49b9-88DD-029876E11C01}";
FileDialog.FOS nOptions = (FileDialog.FOS.FOS_FORCESHOWHIDDEN | FileDialog.FOS.FOS_ALLOWMULTISELECT | FileDialog.FOS.FOS_NODEREFERENCELINKS);
//FileDialog.FOS nOptions = FileDialog.FOS.FOS_PICKFOLDERS;
string sFile = null;
object sFileNames = new System.Collections.ObjectModel.Collection<string>();
FileDialog.IShellItem si = null;
FileDialog.IShellItemArray sia = null;
fileDialog = new FileDialog(nOptions, "Title", sFolder);
if ((fileDialog.ShowDialog(this.Handle) == DialogResult.OK))
{
listBox1.Items.Clear();
if (fileDialog.FileName != null)
{
sFile = fileDialog.FileName;
si = fileDialog.ShellItem;
listBox1.Items.Add(sFile);
// Test copy 1 file to Documents folder
IFileOperation pfo;
Guid CLSID_FileOperation = new Guid("3ad05575-8857-4850-9277-11b85bdb8e09");
Type fileOperationType = Type.GetTypeFromCLSID(CLSID_FileOperation);
pfo = (IFileOperation)Activator.CreateInstance(fileOperationType);
Guid GUID_IShellItem = typeof(FileDialog.IShellItem).GUID;
IntPtr psi = IntPtr.Zero;
Guid FOLDERID_Documents = new Guid("FDD39AD0-238F-46AF-ADB4-6C85480369C7");
SHGetKnownFolderItem(ref FOLDERID_Documents, KNOWN_FOLDER_FLAG.KF_FLAG_DEFAULT, IntPtr.Zero, ref GUID_IShellItem, ref psi);
if (psi != IntPtr.Zero)
{
FileDialog.IShellItem pShellItemDest = (FileDialog.IShellItem)Marshal.GetObjectForIUnknown(psi);
HRESULT hr = pfo.CopyItem(si, pShellItemDest, null, IntPtr.Zero);
hr = pfo.PerformOperations();
Marshal.ReleaseComObject(pShellItemDest);
}
Marshal.ReleaseComObject(pfo);
Marshal.ReleaseComObject(si);
}
else if (fileDialog.FileNames != null)
{
sia = fileDialog.ShellItemArray;
sFileNames = fileDialog.FileNames;
int nCount = ((System.Collections.ObjectModel.Collection<string>)sFileNames).Count;
for (int n = 0; n < nCount; n++)
{
string sFileName = ((System.Collections.ObjectModel.Collection<string>)sFileNames).ElementAt(n);
listBox1.Items.Add(sFileName);
}
// Test copy n files to Documents folder
IFileOperation pfo;
Guid CLSID_FileOperation = new Guid("3ad05575-8857-4850-9277-11b85bdb8e09");
Type fileOperationType = Type.GetTypeFromCLSID(CLSID_FileOperation);
pfo = (IFileOperation)Activator.CreateInstance(fileOperationType);
Guid GUID_IShellItem = typeof(FileDialog.IShellItem).GUID;
IntPtr psi = IntPtr.Zero;
Guid FOLDERID_Documents = new Guid("FDD39AD0-238F-46AF-ADB4-6C85480369C7");
SHGetKnownFolderItem(ref FOLDERID_Documents, KNOWN_FOLDER_FLAG.KF_FLAG_DEFAULT, IntPtr.Zero, ref GUID_IShellItem, ref psi);
if (psi != IntPtr.Zero)
{
FileDialog.IShellItem pShellItemDest = (FileDialog.IShellItem)Marshal.GetObjectForIUnknown(psi);
HRESULT hr = pfo.CopyItems(sia, pShellItemDest);
hr = pfo.PerformOperations();
Marshal.ReleaseComObject(pShellItemDest);
}
Marshal.ReleaseComObject(pfo);
Marshal.ReleaseComObject(sia);
}
}
}
public class FileDialog
{
public FileDialog(FOS nOptions = 0, string sTitle = null, string sFolder = null)
{
Options = nOptions;
Title = sTitle;
Folder = sFolder;
FileNames = new System.Collections.ObjectModel.Collection<string>();
}
public FOS Options { get; set; }
public string Title { get; set; }
public string Folder { get; set; }
public string FileName { get; set; }
public System.Collections.ObjectModel.Collection<string> FileNames { get; set; }
public IShellItem ShellItem { get; set; }
public IShellItemArray ShellItemArray { get; set; }
private DialogEventSink eventSink;
public DialogResult ShowDialog(IntPtr hwndOwner)
{
HRESULT hr = HRESULT.E_FAIL;
IFileOpenDialog fod = (IFileOpenDialog)new FileOpenDialog();
try
{
FOS nOptions = 0;
hr = fod.GetOptions(out nOptions);
nOptions = nOptions | Options;
hr = fod.SetOptions(nOptions);
if (!string.IsNullOrEmpty(Title))
hr = fod.SetTitle(Title);
if (!string.IsNullOrEmpty(Folder))
{
Guid GUID_IShellItem = typeof(IShellItem).GUID;
IntPtr psi = IntPtr.Zero;
hr = SHCreateItemFromParsingName(Folder, IntPtr.Zero, ref GUID_IShellItem, ref psi);
if ((hr == HRESULT.S_OK))
{
IShellItem si = (IShellItem)Marshal.GetObjectForIUnknown(psi);
hr = fod.SetFolder(si);
Marshal.ReleaseComObject(si);
}
}
uint nCookie;
eventSink = new DialogEventSink(this);
hr = fod.Advise(eventSink, out nCookie);
eventSink.Cookie = nCookie;
IFileDialogCustomize pfdc;
pfdc = (IFileDialogCustomize)fod;
//hr = pfdc.AddPushButton(601, " Return selected items ");
hr = fod.Show(hwndOwner);
if ((hr == HRESULT.S_OK))
{
IShellItem pShellItemResult = null;
System.Text.StringBuilder sbResult = new System.Text.StringBuilder(MAX_PATH);
hr = fod.GetResult(out pShellItemResult);
if ((hr == HRESULT.S_OK))
{
ShellItem = pShellItemResult;
hr = pShellItemResult.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, ref sbResult);
if ((hr == HRESULT.S_OK))
{
FileName = sbResult.ToString();
}
else
{
hr = pShellItemResult.GetDisplayName(SIGDN.SIGDN_NORMALDISPLAY, ref sbResult);
if ((hr == HRESULT.S_OK))
{
FileName = sbResult.ToString();
}
}
//Marshal.ReleaseComObject(pShellItemResult);
}
else if (hr == HRESULT.E_UNEXPECTED)
{
IShellItemArray pShellItemArrayResult = null;
hr = fod.GetResults(out pShellItemArrayResult);
if ((hr == HRESULT.S_OK))
{
ShellItemArray = pShellItemArrayResult;
int nCount = 0;
hr = pShellItemArrayResult.GetCount(ref nCount);
for (int i = 0; i <= nCount - 1; i++)
{
IShellItem si = null;
hr = pShellItemArrayResult.GetItemAt(i, ref si);
if (hr == HRESULT.S_OK)
{
hr = si.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, ref sbResult);
if ((hr == HRESULT.S_OK))
{
FileNames.Add(sbResult.ToString());
}
else
{
hr = si.GetDisplayName(SIGDN.SIGDN_NORMALDISPLAY, ref sbResult);
if ((hr == HRESULT.S_OK))
{
FileNames.Add(sbResult.ToString());
}
}
}
}
}
}
}
else if (hr == HRESULT.E_CANCELLED)
return DialogResult.Cancel;
return DialogResult.OK;
}
finally
{
Marshal.ReleaseComObject(fod);
}
}
[DllImport("Shell32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern HRESULT SHCreateItemFromParsingName(string pszPath, IntPtr pbc, ref Guid riid, ref IntPtr ppv);
public const int MAX_PATH = 260;
public const uint ERROR_CANCELLED = 1223;
public enum HRESULT : uint
{
S_OK = 0,
S_FALSE = 1,
E_NOINTERFACE = 0x80004002,
E_NOTIMPL = 0x80004001,
E_FAIL = 0x80004005,
E_INVALIDARG = 0x80070057,
E_CANCELLED = 0x80070000 + ERROR_CANCELLED,
E_UNEXPECTED = 0x8000FFFF
}
private class DialogEventSink : IFileDialogEvents, IFileDialogControlEvents
{
private FileDialog parent;
public DialogEventSink(FileDialog fileDialog)
{
this.parent = fileDialog;
}
public uint Cookie { get; set; }
public HRESULT OnFileOk([In][MarshalAs(UnmanagedType.Interface)] IFileDialog pfd)
{
return HRESULT.S_OK;
}
public HRESULT OnFolderChanging([In][MarshalAs(UnmanagedType.Interface)] IFileDialog pfd, [In][MarshalAs(UnmanagedType.Interface)] IShellItem psiFolder)
{
//System.Text.StringBuilder sbResult = new System.Text.StringBuilder(MAX_PATH);
return HRESULT.S_OK;
}
// If defined as Function => "Attempted to read or write protected memory. This is often an indication that other memory is corrupt "
public void OnFolderChange([In][MarshalAs(UnmanagedType.Interface)] IFileDialog pfd)
{
}
public void OnSelectionChange([In][MarshalAs(UnmanagedType.Interface)] IFileDialog pfd)
{
}
public void OnShareViolation([In][MarshalAs(UnmanagedType.Interface)] IFileDialog pfd, [In][MarshalAs(UnmanagedType.Interface)] IShellItem psi, out FDE_SHAREVIOLATION_RESPONSE pResponse)
{
//throw new NotImplementedException();
pResponse = FDE_SHAREVIOLATION_RESPONSE.FDESVR_DEFAULT;
}
public void OnTypeChange([In][MarshalAs(UnmanagedType.Interface)] IFileDialog pfd)
{
//throw new NotImplementedException();
}
public void OnOverwrite([In][MarshalAs(UnmanagedType.Interface)] IFileDialog pfd, [In][MarshalAs(UnmanagedType.Interface)] IShellItem psi, out FDE_OVERWRITE_RESPONSE pResponse)
{
//throw new NotImplementedException();
pResponse = FDE_OVERWRITE_RESPONSE.FDEOR_DEFAULT;
}
public HRESULT OnItemSelected([In][MarshalAs(UnmanagedType.Interface)] IFileDialogCustomize pfdc, [In] int dwIDCtl, [In] int dwIDItem)
{
//throw new NotImplementedException();
return HRESULT.S_OK;
}
// If defined as Function => "Attempted to read or write protected memory. This is often an indication that other memory is corrupt "
public void OnButtonClicked([In][MarshalAs(UnmanagedType.Interface)] IFileDialogCustomize pfdc, [In] int dwIDCtl)
{
//switch (dwIDCtl)
//{
// // defined in AddPushButton
// case 601:
// {
// break;
// }
// default:
// {
// break;
// }
//}
}
public HRESULT OnCheckButtonToggled([In][MarshalAs(UnmanagedType.Interface)] IFileDialogCustomize pfdc, [In] int dwIDCtl, [In] bool bChecked)
{
//throw new NotImplementedException();
return HRESULT.S_OK;
}
public HRESULT OnControlActivating([In][MarshalAs(UnmanagedType.Interface)] IFileDialogCustomize pfdc, [In] int dwIDCtl)
{
//throw new NotImplementedException();
return HRESULT.S_OK;
}
}
[ComImport]
[Guid("b4db1657-70d7-485e-8e3e-6fcb5a5c1802")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IModalWindow
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.InternalCall, MethodCodeType = System.Runtime.CompilerServices.MethodCodeType.Runtime)]
[PreserveSig]
uint Show([In] IntPtr hwndOwner);
}
[ComImport]
[Guid("42f85136-db7e-439c-85f1-e4075d135fc8")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IFileDialog : IModalWindow
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.InternalCall, MethodCodeType = System.Runtime.CompilerServices.MethodCodeType.Runtime)]
[PreserveSig]
new HRESULT Show([In] IntPtr parent);
HRESULT SetFileTypes([In] uint cFileTypes, [In][MarshalAs(UnmanagedType.LPArray)] COMDLG_FILTERSPEC[] rgFilterSpec);
HRESULT SetFileTypeIndex([In] uint iFileType);
HRESULT GetFileTypeIndex(out uint piFileType);
HRESULT Advise([In][MarshalAs(UnmanagedType.Interface)] IFileDialogEvents pfde, out uint pdwCookie);
HRESULT Unadvise([In] uint dwCookie);
HRESULT SetOptions([In] FOS fos);
HRESULT GetOptions(out FOS pfos);
HRESULT SetDefaultFolder([In][MarshalAs(UnmanagedType.Interface)] IShellItem psi);
HRESULT SetFolder([In][MarshalAs(UnmanagedType.Interface)] IShellItem psi);
HRESULT GetFolder([MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi);
HRESULT GetCurrentSelection([MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi);
HRESULT SetFileName([In][MarshalAs(UnmanagedType.LPWStr)] string pszName);
HRESULT GetFileName([MarshalAs(UnmanagedType.LPWStr)] out string pszName);
HRESULT SetTitle([In][MarshalAs(UnmanagedType.LPWStr)] string pszTitle);
HRESULT SetOkButtonLabel([In][MarshalAs(UnmanagedType.LPWStr)] string pszText);
HRESULT SetFileNameLabel([In][MarshalAs(UnmanagedType.LPWStr)] string pszLabel);
[PreserveSig]
HRESULT GetResult([MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi);
HRESULT AddPlace([In][MarshalAs(UnmanagedType.Interface)] IShellItem psi, FDAP fdap);
HRESULT SetDefaultExtension([In][MarshalAs(UnmanagedType.LPWStr)] string pszDefaultExtension);
HRESULT Close([MarshalAs(UnmanagedType.Error)] int hr);
HRESULT SetClientGuid([In] ref Guid guid);
HRESULT ClearClientData();
HRESULT SetFilter([MarshalAs(UnmanagedType.Interface)] IntPtr pFilter);
}
public enum FDAP
{
FDAP_BOTTOM,
FDAP_TOP
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct COMDLG_FILTERSPEC
{
[MarshalAs(UnmanagedType.LPWStr)]
public string pszName;
[MarshalAs(UnmanagedType.LPWStr)]
public string pszSpec;
}
public enum FOS : uint
{
FOS_OVERWRITEPROMPT = 0x2,
FOS_STRICTFILETYPES = 0x4,
FOS_NOCHANGEDIR = 0x8,
FOS_PICKFOLDERS = 0x20,
FOS_FORCEFILESYSTEM = 0x40,
FOS_ALLNONSTORAGEITEMS = 0x80,
FOS_NOVALIDATE = 0x100,
FOS_ALLOWMULTISELECT = 0x200,
FOS_PATHMUSTEXIST = 0x800,
FOS_FILEMUSTEXIST = 0x1000,
FOS_CREATEPROMPT = 0x2000,
FOS_SHAREAWARE = 0x4000,
FOS_NOREADONLYRETURN = 0x8000,
FOS_NOTESTFILECREATE = 0x10000,
FOS_HIDEMRUPLACES = 0x20000,
FOS_HIDEPINNEDPLACES = 0x40000,
FOS_NODEREFERENCELINKS = 0x100000,
FOS_OKBUTTONNEEDSINTERACTION = 0x200000, // Only enable the OK button If the user has done something In the view.
FOS_DONTADDTORECENT = 0x2000000,
FOS_FORCESHOWHIDDEN = 0x10000000,
FOS_DEFAULTNOMINIMODE = 0x20000000, // (Not used In Win7)
FOS_FORCEPREVIEWPANEON = 0x40000000,
FOS_SUPPORTSTREAMABLEITEMS = 0x80000000 // Indicates the caller will use BHID_Stream To open contents, no need To download the file
}
[ComImport()]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE")]
public interface IShellItem
{
HRESULT BindToHandler(IntPtr pbc, ref Guid bhid, ref Guid riid, ref IntPtr ppv);
HRESULT GetParent(ref IShellItem ppsi);
[PreserveSig]
HRESULT GetDisplayName(SIGDN sigdnName, ref System.Text.StringBuilder ppszName);
HRESULT GetAttributes(uint sfgaoMask, ref uint psfgaoAttribs);
HRESULT Compare(IShellItem psi, uint hint, ref int piOrder);
}
public enum SIGDN : uint
{
SIGDN_NORMALDISPLAY = 0x0,
SIGDN_PARENTRELATIVEPARSING = 0x80018001,
SIGDN_DESKTOPABSOLUTEPARSING = 0x80028000,
SIGDN_PARENTRELATIVEEDITING = 0x80031001,
SIGDN_DESKTOPABSOLUTEEDITING = 0x8004C000,
SIGDN_FILESYSPATH = 0x80058000,
SIGDN_URL = 0x80068000,
SIGDN_PARENTRELATIVEFORADDRESSBAR = 0x8007C001,
SIGDN_PARENTRELATIVE = 0x80080001
}
[ComImport]
[Guid("973510DB-7D7F-452B-8975-74A85828D354")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IFileDialogEvents
{
[PreserveSig]
HRESULT OnFileOk([In][MarshalAs(UnmanagedType.Interface)] IFileDialog pfd);
[PreserveSig]
HRESULT OnFolderChanging([In][MarshalAs(UnmanagedType.Interface)] IFileDialog pfd, [In][MarshalAs(UnmanagedType.Interface)] IShellItem psiFolder);
// If defined as Function => "Attempted to read or write protected memory. This is often an indication that other memory is corrupt "
void OnFolderChange([In][MarshalAs(UnmanagedType.Interface)] IFileDialog pfd);
void OnSelectionChange([In][MarshalAs(UnmanagedType.Interface)] IFileDialog pfd);
void OnShareViolation([In][MarshalAs(UnmanagedType.Interface)] IFileDialog pfd, [In][MarshalAs(UnmanagedType.Interface)] IShellItem psi, out FDE_SHAREVIOLATION_RESPONSE pResponse);
void OnTypeChange([In][MarshalAs(UnmanagedType.Interface)] IFileDialog pfd);
void OnOverwrite([In][MarshalAs(UnmanagedType.Interface)] IFileDialog pfd, [In][MarshalAs(UnmanagedType.Interface)] IShellItem psi, out FDE_OVERWRITE_RESPONSE pResponse);
}
public enum FDE_SHAREVIOLATION_RESPONSE
{
FDESVR_DEFAULT = 0x0,
FDESVR_ACCEPT = 0x1,
FDESVR_REFUSE = 0x2
}
public enum FDE_OVERWRITE_RESPONSE
{
FDEOR_DEFAULT = 0x0,
FDEOR_ACCEPT = 0x1,
FDEOR_REFUSE = 0x2
}
[ComImport]
[Guid("36116642-D713-4b97-9B83-7484A9D00433")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IFileDialogControlEvents
{
HRESULT OnItemSelected([In][MarshalAs(UnmanagedType.Interface)] IFileDialogCustomize pfdc, [In] int dwIDCtl, [In] int dwIDItem);
// If defined as Function => "Attempted to read or write protected memory. This is often an indication that other memory is corrupt "
void OnButtonClicked([In][MarshalAs(UnmanagedType.Interface)] IFileDialogCustomize pfdc, [In] int dwIDCtl);
HRESULT OnCheckButtonToggled([In][MarshalAs(UnmanagedType.Interface)] IFileDialogCustomize pfdc, [In] int dwIDCtl, [In] bool bChecked);
HRESULT OnControlActivating([In][MarshalAs(UnmanagedType.Interface)] IFileDialogCustomize pfdc, [In] int dwIDCtl);
}
[ComImport]
[Guid("e6fdd21a-163f-4975-9c8c-a69f1ba37034")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IFileDialogCustomize
{
HRESULT EnableOpenDropDown([In] int dwIDCtl