[英]How can i get the Process used to open a file in C#
我試圖用他們的相關應用程序打開不同的文件,如下所示:
ProcessPath = @"C:\Users\Public\Pictures\Sample Pictures\Tulips.jpg";
ProcessStartInfo processStartInfo = new ProcessStartInfo();
processStartInfo.FileName = ProcessPath;
processStartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(ProcessPath);
process = new Process();
process.StartInfo = processStartInfo;
process.EnableRaisingEvents = true;
process.Exited += Process_Exited;
process.Start();
請幫助您掌握代表打開的應用程序的Process對象,因為在調用process.Start()之后 流程中的大多數字段都拋出異常。
謝謝。
我設法找到一個解決方案:
使用Windows API函數
[DllImport("shell32.dll")]
static extern int FindExecutable(string file, string directory, [Out] StringBuilder lpResult);
返回給定文件的關聯應用程序路徑。 然后,我可以使用發布的原始代碼與作為參數傳遞的原始文件執行該關聯的應用程序!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.