User Tools

Site Tools

blog:2013-06-18_c_opening_folder_on_file_explorer



2013-06-18 C#: Opening Folder on File Explorer

  • I want open Windows Explorer into the selected folder.
  • The code as follows:
  •             string path = "c:/temp/";
                path = path.Replace("/", "\\");
                FileInfo fileInfo = new FileInfo(path);
    
                //check if directory exists so that 'fileInfo.Directory' doesn't throw directory not found
    
                ProcessStartInfo pi = new ProcessStartInfo("explorer.exe")
                {
                    WindowStyle = ProcessWindowStyle.Normal,
                    UseShellExecute = true,
                    FileName = fileInfo.Directory.FullName,
                    Verb = "open"
                };
    
                try
                {
                    Process.Start(pi);
                    Thread.Sleep(500); // can set any delay here
                    SendKeys.SendWait(fileInfo.Name);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message, ex);
                }

TAGS

  • 46 person(s) visited this page until now.

Permalink blog/2013-06-18_c_opening_folder_on_file_explorer.txt · Last modified: 2023/06/18 18:34 by jethro

oeffentlich