Opens Windows Explorer window with specified path. - CSharp System.Windows.Forms

CSharp examples for System.Windows.Forms:Dialog

Description

Opens Windows Explorer window with specified path.

Demo Code


using System.Windows.Forms;
using System.IO;/*  www .  j  a  v a 2 s. c o  m*/
using System.Diagnostics;

public class Main{
        /// <summary>
        /// Opens Windows Explorer window with specified path.
        /// </summary>
        public static void StartExplorer(string path)
        {
            if (string.IsNullOrEmpty(path))
                return;

            // if specified directory doesn't exist, create it:
            try
            {
                if (!Directory.Exists(path))
                    Directory.CreateDirectory(path);
            }
            catch
            {
            }

            // open Explorer window with this folder:
            Process.Start("Explorer.exe", "/e,\"" + path + "\"");
        }
}

Related Tutorials