예제 #1
0
 /// <summary>
 /// Create and show the browse dialog, and set the Directory property with the 
 /// result.</summary>
 private void Browse()
 {
     // use default win32 dialog
     var d = new BrowseForFolderDialog();
     d.InitialFolder = Directory;
     if (true == d.ShowDialog(Application.Current.MainWindow))
     {
         Directory = d.SelectedFolder;
     }
 }
        /// <summary>
        /// Create and show the browse dialog, and set the Directory property with the
        /// result.</summary>
        private void Browse()
        {
            // use default win32 dialog
            var d = new BrowseForFolderDialog();

            d.InitialFolder = Directory;
            if (true == d.ShowDialog(Application.Current.MainWindow))
            {
                Directory = d.SelectedFolder;
            }
        }
예제 #3
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;
        }