private void OpenImage(string fileName) { try { Process.Start(fileName); } catch (Exception ex) { // LogHelper.WriteLog("调用默认看图软件打开失败", ex); try { string arg = string.Format( "\"{0}\\Windows Photo Viewer\\PhotoViewer.dll\", ImageView_Fullscreen {1} ", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) , fileName); var dllExe = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "rundll32.exe"); // LogHelper.WriteLog(string.Format("调用系统默认的图片查看器打开图片,参数为:{0} {1}", dllExe, arg)); System.Diagnostics.Process.Start(dllExe, arg); } catch (Exception e) { // LogHelper.WriteLog("系统图片查看器打开图片失败", ex); //打开文件夹并选中文件 var argment = string.Format(@"/select,""{0}""", fileName); System.Diagnostics.Process.Start("Explorer", argment); } } }
说明,这个代码适用于程序的目标平台为x86
如果是x64,那么就需要做适当修改
原文地址:https://www.cnblogs.com/sczmzx/p/10340866.html
时间: 2024-10-10 20:40:29