最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#實(shí)現(xiàn)打開指定目錄和指定文件的示例代碼

 更新時(shí)間:2022年06月29日 16:53:14   作者:牛奶咖啡13  
這篇文章主要為大家詳細(xì)介紹了如何利用C#實(shí)現(xiàn)打開指定目錄、打開指定目錄且選中指定文件、打開指定文件,感興趣的小伙伴可以嘗試一下

一、實(shí)現(xiàn)內(nèi)容

1.1實(shí)現(xiàn)的功能

想要實(shí)現(xiàn):

①打開指定的目錄;

②打開指定的目錄且選中指定文件;

③打開指定文件

1.2實(shí)現(xiàn)的效果

二、實(shí)現(xiàn)操作

        /// <summary>
        /// 打開目錄
        /// </summary>
        /// <param name="folderPath">目錄路徑(比如:C:\Users\Administrator\)</param>
        private static void OpenFolder(string folderPath)
        {
            if (string.IsNullOrEmpty(folderPath)) return;
 
            Process process = new Process();
            ProcessStartInfo psi = new ProcessStartInfo("Explorer.exe");
            psi.Arguments = folderPath;
            process.StartInfo = psi;
 
            try
            {
                process.Start();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                process?.Close();
 
            }
 
        }
 
        /// <summary>
        /// 打開目錄且選中文件
        /// </summary>
        /// <param name="filePathAndName">文件的路徑和名稱(比如:C:\Users\Administrator\test.txt)</param>
        private static void OpenFolderAndSelectedFile(string filePathAndName)
        {
            if (string.IsNullOrEmpty(filePathAndName)) return;
 
            Process process = new Process();
            ProcessStartInfo psi = new ProcessStartInfo("Explorer.exe");
            psi.Arguments = "/e,/select,"+filePathAndName;
            process.StartInfo = psi;
 
            //process.StartInfo.UseShellExecute = true;
            try
            {
                process.Start();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                process?.Close();
 
            }
        }
 
        /// <summary>
        /// 打開文件
        /// </summary>
        /// <param name="filePathAndName">文件的路徑和名稱(比如:C:\Users\Administrator\test.txt)</param>
        /// <param name="isWaitFileClose">是否等待文件關(guān)閉(true:表示等待)</param>
        private static void OpenFile(string filePathAndName,bool isWaitFileClose=true)
        {
            Process process = new Process();
            ProcessStartInfo psi = new ProcessStartInfo(filePathAndName);
            process.StartInfo = psi;
 
            process.StartInfo.UseShellExecute = true;
 
            try
            {
                process.Start();
 
                //等待打開的程序關(guān)閉
                if (isWaitFileClose)
                {
                    process.WaitForExit();
                }
                
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                process?.Close();
               
            }
        }

三、Windows 資源管理器參數(shù)說明

Windows資源管理器參數(shù)的說明

序號(hào)參數(shù)命令說明
1Explorer /n此命令使用默認(rèn)設(shè)置打開一個(gè)資源管理器窗口。顯示的內(nèi)容通常是安裝 Windows 的驅(qū)動(dòng)器的根目錄
2Explorer /e此命令使用默認(rèn)視圖啟動(dòng) Windows 資源管理器
3Explorer /e,C:\Windows此命令使用默認(rèn)視圖啟動(dòng) Windows 資源管理器,并把焦點(diǎn)定位在 C:\Windows路徑上
4Explorer /root, C:\Windows\Cursors此命令啟動(dòng) Windows 資源管理器后焦點(diǎn)定位在 C:\Windows\Cursors folder路徑上。此示例使用 C:\Windows\Cursors 作為 Windows 資源管理器的“根”目錄
5Explorer /select, C:\Windows\Cursors\banana.ani此命令啟動(dòng) Windows 資源管理器后選定“C:\Windows\Cursors\banana.ani”文件。
6Explorer /root, \\server\share, select, Program.exe此命令啟動(dòng) Windows 資源管理器時(shí)以遠(yuǎn)程共享作為“根”文件夾,而且 Program.exe 文件將被選中

以上就是C#實(shí)現(xiàn)打開指定目錄和指定文件的示例代碼的詳細(xì)內(nèi)容,更多關(guān)于C#打開指定目錄 文件的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論

桂林市| 伊宁市| 资兴市| 陕西省| 徐闻县| 永昌县| 昌黎县| 黑山县| 南丰县| 咸丰县| 西藏| 西青区| 靖江市| 大悟县| 钦州市| 高碑店市| 宁化县| 启东市| 集安市| 巴林右旗| 呼和浩特市| 响水县| 绥滨县| 柳河县| 石林| 广南县| 汶上县| 丰都县| 安达市| 张北县| 彭州市| 长乐市| 尼勒克县| 开原市| 靖边县| 诸城市| 孙吴县| 姚安县| 新干县| 孟连| 合肥市|