Beispiel #1
0
        /// <exception cref="FileNotFoundException">path not found.</exception>
        /// <exception cref="COMException">See HRESULT value for more details.</exception>
        public void AddPlaceFromPath(string path, bool top = false)
        {
            var shellItem = ComHelper.ShellItemFromPath(path);

            _dialog.AddPlace(shellItem, top ? FDAP.TOP : FDAP.BOTTOM);
            Marshal.ReleaseComObject(shellItem);
        }
        /// <summary>
        /// Adds a location, such as a folder, library, search connector, or known folder, to the list of
        /// places available for a user to open or save items. This method actually adds an item
        /// to the <b>Favorite Links</b> or <b>Places</b> section of the Open/Save dialog.
        /// </summary>
        /// <param name="place">The item to add to the places list.</param>
        /// <param name="location">One of the enumeration values that indicates placement of the item in the list.</param>
        public void AddPlace(ShellContainer place, FileDialogAddPlaceLocation location)
        {
            if (place == null)
            {
                throw new ArgumentNullException("place");
            }

            // Get our native dialog
            if (nativeDialog == null)
            {
                InitializeNativeFileDialog();
                nativeDialog = GetNativeFileDialog();
            }

            // Add the shellitem to the places list
            if (nativeDialog != null)
            {
                nativeDialog.AddPlace(place.NativeShellItem, (ShellNativeMethods.FileDialogAddPlacement)location);
            }
        }
Beispiel #3
0
        internal virtual void PrepareVistaDialog(IFileDialog dialog)
        {
            dialog.SetDefaultExtension(this.DefaultExt);
            dialog.SetFileName(this.CriticalFileName);
            if (!string.IsNullOrEmpty(this.InitialDirectory))
            {
                IShellItem shellItemForPath = ShellUtil.GetShellItemForPath(this.InitialDirectory);
                if (shellItemForPath != null)
                {
                    dialog.SetDefaultFolder(shellItemForPath);
                    dialog.SetFolder(shellItemForPath);
                }
            }
            dialog.SetTitle(this.Title);
            FOS options = (FOS)((this.Options & 1063690) | 536870912 | 64);

            dialog.SetOptions(options);
            COMDLG_FILTERSPEC[] filterItems = FileDialog.GetFilterItems(this.Filter);
            if (filterItems.Length != 0)
            {
                dialog.SetFileTypes((uint)filterItems.Length, filterItems);
                dialog.SetFileTypeIndex((uint)this.FilterIndex);
            }
            IList <FileDialogCustomPlace> customPlaces = this.CustomPlaces;

            if (customPlaces != null && customPlaces.Count != 0)
            {
                foreach (FileDialogCustomPlace customPlace in customPlaces)
                {
                    IShellItem shellItem = FileDialog.ResolveCustomPlace(customPlace);
                    if (shellItem != null)
                    {
                        try
                        {
                            dialog.AddPlace(shellItem, FDAP.BOTTOM);
                        }
                        catch (ArgumentException)
                        {
                        }
                    }
                }
            }
        }
        internal void Apply(IFileDialog dialog)
        {
            // Walk backwards
            for (int i = Items.Count - 1; i >= 0; --i)
            {
                FileDialogCustomPlace customPlace = Items[i];

                try
                {
                    IShellItem?shellItem = customPlace.GetNativePath();
                    if (shellItem is not null)
                    {
                        dialog.AddPlace(shellItem, 0);
                    }
                }
                catch (FileNotFoundException)
                {
                    // Silently absorb FileNotFound exceptions (these could be caused by a
                    // path that disappeared after the place was added to the dialog).
                }
            }
        }
        internal virtual void PrepareVistaDialog(IFileDialog dialog)
        {
            dialog.SetDefaultExtension(DefaultExt);

            dialog.SetFileName(CriticalFileName);

            if (!string.IsNullOrEmpty(InitialDirectory))
            {
                IShellItem initialDirectory = ShellUtil.GetShellItemForPath(InitialDirectory);
                if (initialDirectory != null)
                {
                    // Setting both of these so the dialog doesn't display errors when a remembered folder is missing.
                    dialog.SetDefaultFolder(initialDirectory);
                    dialog.SetFolder(initialDirectory);
                }
            }

            dialog.SetTitle(Title);

            // Force no mini mode for the SaveFileDialog.
            // Only accept physically backed locations.
            FOS options = ((FOS)Options & c_VistaFileDialogMask) | FOS.DEFAULTNOMINIMODE | FOS.FORCEFILESYSTEM;
            dialog.SetOptions(options);
            
            COMDLG_FILTERSPEC[] filterItems = GetFilterItems(Filter);
            if (filterItems.Length > 0)
            {
                dialog.SetFileTypes((uint)filterItems.Length, filterItems);
                dialog.SetFileTypeIndex(unchecked((uint)FilterIndex));
            }

            IList<FileDialogCustomPlace> places = CustomPlaces;
            if (places != null && places.Count != 0)
            {
                foreach (FileDialogCustomPlace customPlace in places)
                {
                    IShellItem shellItem = ResolveCustomPlace(customPlace);
                    if (shellItem != null)
                    {
                        try
                        {
                            dialog.AddPlace(shellItem, FDAP.BOTTOM);
                        }
                        catch (ArgumentException)
                        {
                            // The dialog doesn't allow some ShellItems to be set as Places (like device ports).
                            // Silently ---- errors here.
                        }
                    }
                }
            }
        }