示例#1
0
        private void BrowseDirectoryButton_Click(object sender, EventArgs e)
        {
            string directory = BrowseForFolderDialog.Show(
                this,
                "Directory to convert",
                BrowseForFolderOptions.EditBox |
                BrowseForFolderOptions.NewDialogStyle |
                BrowseForFolderOptions.NoNewFolderButton |
                BrowseForFolderOptions.ReturnOnlyFileSystemDirectories |
                BrowseForFolderOptions.UseNewUI
                );

            if (directory != null)
            {
                _directory.Text = directory;
            }
        }
示例#2
0
        /// <summary>
        /// Searches all the files, starting from a user-selected directory, for the filename
        /// specified by 'uri'</summary>
        /// <param name="uri"></param>
        /// <param name="newUri">either 'uri' or a replacement URI</param>
        /// <param name="askUser">asks the user for the search directory. If false, the user
        /// will only be asked the first time.</param>
        /// <returns>true if a replacement was chosen, otherwise false</returns>
        private static bool SearchForFile(Uri uri, out Uri newUri, bool askUser)
        {
            // default return value
            newUri = uri;

            // ask the user for a directory to search in or use last search
            bool doSearch = true;

            if (askUser || s_searchRoot == string.Empty)
            {
                var dlg = new BrowseForFolderDialog
                {
                    InitialFolder =
                        s_searchRoot != string.Empty
                                        ? s_searchRoot
                                        : Directory.GetCurrentDirectory()
                };

                if (dlg.ShowDialog(Application.Current.MainWindow) == true)
                {
                    s_searchRoot = dlg.SelectedFolder;
                }
                else
                {
                    doSearch = false;
                }
            }

            // do the search and if successful, add the result to our mapping
            if (doSearch)
            {
                string searchName = Path.GetFileName(uri.LocalPath);
                foreach (string newPath in DirectoryUtil.GetFilesIteratively(s_searchRoot, searchName))
                {
                    // The search can be stopped after the first match.
                    newUri = new Uri(newPath);
                    s_localPathMap.Add(uri.LocalPath, newUri);
                    return(true);
                }
            }

            return(false);
        }
示例#3
0
 /// <summary>
 /// The browse.
 /// </summary>
 private void Browse()
 {
     if (FolderBrowserDialogService != null)
     {
         var directory = Directory;
         if (FolderBrowserDialogService.ShowFolderBrowserDialog(ref directory))
         {
             Directory = directory;
         }
     }
     else
     {
         // use default win32 dialog
         var d = new BrowseForFolderDialog();
         d.InitialFolder = Directory;
         if (true == d.ShowDialog())
         {
             Directory = d.SelectedFolder;
         }
     }
 }