コード例 #1
0
        private static String ShowDialogInner(IFileOpenDialog dialog, IntPtr parentHWnd, String title, String initialDirectory)
#endif
        {
            //IFileDialog ifd = dialog;
            FileOpenOptions flags =
                FileOpenOptions.NoTestFileCreate |
                FileOpenOptions.PathMustExist |
                FileOpenOptions.PickFolders |
                FileOpenOptions.ForceFilesystem;

            dialog.SetOptions(flags);

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

            if (initialDirectory != null)
            {
#if NETCOREAPP3_1_OR_GREATER
                IShellItem2?initialDirectoryShellItem = Utility.ParseShellItem2Name(initialDirectory);
#else
                IShellItem2 initialDirectoryShellItem = Utility.ParseShellItem2Name(initialDirectory);
#endif
                if (initialDirectoryShellItem != null)
                {
                    dialog.SetFolder(initialDirectoryShellItem);
                }
            }

            //

            HResult hr = dialog.Show(parentHWnd);
            if (hr.ValidateDialogShowHResult())
            {
                dialog.GetResults(out IShellItemArray resultsArray);

#if NETCOREAPP3_1_OR_GREATER
                IReadOnlyList <String?> fileNames = Utility.GetFileNames(resultsArray);
#else
                IReadOnlyList <String> fileNames = Utility.GetFileNames(resultsArray);
#endif
                if (fileNames.Count == 0)
                {
                    return(null);
                }
                else
                {
                    return(fileNames[0]);
                }
            }
            else
            {
                // User cancelled.
                return(null);
            }
        }
コード例 #2
0
        private static IReadOnlyList <String> ShowDialogInner(IFileOpenDialog dialog, IntPtr parentHWnd, String title, String initialDirectory, String defaultFileName, IReadOnlyCollection <Filter> filters, Int32 selectedFilterZeroBasedIndex, FileOpenOptions flags)
#endif
        {
            flags = flags |
                    FileOpenOptions.NoTestFileCreate |
                    FileOpenOptions.PathMustExist |
                    FileOpenOptions.ForceFilesystem;

            dialog.SetOptions(flags);

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

            if (initialDirectory != null)
            {
#if NETCOREAPP3_1_OR_GREATER
                IShellItem2?initialDirectoryShellItem = Utility.ParseShellItem2Name(initialDirectory);
#else
                IShellItem2 initialDirectoryShellItem = Utility.ParseShellItem2Name(initialDirectory);
#endif
                if (initialDirectoryShellItem != null)
                {
                    dialog.SetFolder(initialDirectoryShellItem);
                }
            }

            if (defaultFileName != null)
            {
                dialog.SetFileName(defaultFileName);
            }

            Utility.SetFilters(dialog, filters, selectedFilterZeroBasedIndex);

            //

            HResult hr = dialog.Show(parentHWnd);
            if (hr.ValidateDialogShowHResult())
            {
                dialog.GetResults(out IShellItemArray resultsArray);

                IReadOnlyList <String> fileNames = Utility.GetFileNames(resultsArray);
                return(fileNames);
            }
            else
            {
                // User cancelled.
                return(null);
            }
        }
コード例 #3
0
        private static String ShowDialogInner(IFileSaveDialog dialog, IntPtr parentHWnd, String title, String initialDirectory, String defaultFileName, IReadOnlyCollection <Filter> filters, Int32 selectedFilterZeroBasedIndex = -1)
#endif
        {
            FileOpenOptions flags =
                FileOpenOptions.NoTestFileCreate |
                FileOpenOptions.PathMustExist |
                FileOpenOptions.ForceFilesystem |
                FileOpenOptions.OverwritePrompt;

            dialog.SetOptions(flags);

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

            if (initialDirectory != null)
            {
#if NETCOREAPP3_1_OR_GREATER
                IShellItem2?initialDirectoryShellItem = Utility.ParseShellItem2Name(initialDirectory);
#else
                IShellItem2 initialDirectoryShellItem = Utility.ParseShellItem2Name(initialDirectory);
#endif
                if (initialDirectoryShellItem != null)
                {
                    dialog.SetFolder(initialDirectoryShellItem);
                }
            }

//			if( initialSaveAsItem != null )
//			{
//				IShellItem2 initialSaveAsItemShellItem = Utility.ParseShellItem2Name( initialDirectory );
//				if( initialSaveAsItemShellItem != null )
//				{
//					dialog.SetSaveAsItem( initialSaveAsItemShellItem );
//				}
//			}

            if (defaultFileName != null)
            {
                dialog.SetFileName(defaultFileName);
            }

            Utility.SetFilters(dialog, filters, selectedFilterZeroBasedIndex);

            //

            HResult hr = dialog.Show(parentHWnd);
            if (hr.ValidateDialogShowHResult())
            {
                dialog.GetResult(out IShellItem selectedItem);
                if (selectedItem != null)
                {
                    return(Utility.GetFileNameFromShellItem(selectedItem));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                // User cancelled.
                return(null);
            }
        }