Example #1
0
        private void Configure(IFileOpenDialog dialog)
        {
            dialog.SetOptions(CreateOptions());

            if (!string.IsNullOrEmpty(InitialDirectory))
            {
                var result = NativeMethods.SHCreateItemFromParsingName(InitialDirectory, IntPtr.Zero, typeof(IShellItem).GUID, out var item);
                if (result != NativeMethods.S_OK)
                {
                    throw new Win32Exception(result);
                }

                if (item != null)
                {
                    dialog.SetFolder(item);
                }
            }

            if (Title != null)
            {
                dialog.SetTitle(Title);
            }

            if (OkButtonLabel != null)
            {
                dialog.SetOkButtonLabel(OkButtonLabel);
            }
        }
Example #2
0
        protected override void PerformAction(object parameter)
        {
            var album = parameter as FacebookPhotoAlbum;

            if (album == null)
            {
                return;
            }

            string folderPath = null;

            if (Utility.IsOSVistaOrNewer)
            {
                IFileOpenDialog pFolderDialog = null;
                try
                {
                    pFolderDialog = CLSID.CoCreateInstance <IFileOpenDialog>(CLSID.FileOpenDialog);
                    pFolderDialog.SetOptions(pFolderDialog.GetOptions() | FOS.NOREADONLYRETURN | FOS.PICKFOLDERS);
                    pFolderDialog.SetTitle(string.Format("Select where to save \"{0}\"", album.Title));
                    pFolderDialog.SetOkButtonLabel("Save Album");

                    HRESULT hr = pFolderDialog.Show(new WindowInteropHelper(Application.Current.MainWindow).Handle);
                    if (hr.Failed)
                    {
                        return;
                    }

                    IShellItem pItem = null;
                    try
                    {
                        pItem      = pFolderDialog.GetResult();
                        folderPath = ShellUtil.GetPathFromShellItem(pItem);
                    }
                    finally
                    {
                        Utility.SafeRelease(ref pItem);
                    }
                }
                finally
                {
                    Utility.SafeRelease(ref pFolderDialog);
                }
            }
            else
            {
                var folderDialog = new System.Windows.Forms.FolderBrowserDialog
                {
                    Description         = "Choose where to save the album.",
                    ShowNewFolderButton = true,
                };
                if (folderDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                folderPath = folderDialog.SelectedPath;
            }

            album.SaveToFolder(folderPath, _OnAlbumSaveProgressCallback, null);
            Process.Start(new ProcessStartInfo {
                FileName = folderPath
            });
        }