Exemplo n.º 1
0
        public void OpenFile(string filepath)
        {
            if(File.Exists(filepath))
            {
                try
                {
                    System.Diagnostics.Process.Start(filepath);
                }
                catch(System.ComponentModel.Win32Exception ex)
                {
                    if( ex.NativeErrorCode == 1155 )	// 1155 = ERROR_NO_ASSOCIATION
                    {
                        const int SEE_MASK_NOCLOSEPROCESS = 64,		// 0x00000040
                                  SW_SHOWNORMAL = 1;

                        Shellexecuteinfo ei = new Shellexecuteinfo();
                        ei.cbSize = 60;			// sizeof(SHELLEXECUTEINFO);
                        ei.fMask = SEE_MASK_NOCLOSEPROCESS;
                        ei.lpVerb = "openas";
                        ei.lpFile = filepath;
                        ei.nShow = SW_SHOWNORMAL;			// 1 = SW_SHOWNORMAL

                        int result = ShellExecuteEx(ei);
                    }
                }
            }
            else
                MessageBox.Show("File \"" + filepath + "\" not found!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Exemplo n.º 2
0
 public static extern int ShellExecuteEx(Shellexecuteinfo lpExecInfo);