public string OpenFile(string fileName)

{

    string result = "success";

    string path = System.IO.Path.GetDirectoryName(

        System.Windows.Forms.Application.ExecutablePath) + "\\" + fileName;

    const int ERROR_FILE_NOT_FOUND = 2;

    System.Diagnostics.Process myProcess = new System.Diagnostics.Process();

    try

    {

        myProcess.StartInfo.FileName = path;

        myProcess.StartInfo.Verb = "Open";

        myProcess.StartInfo.CreateNoWindow = true;

        myProcess.Start();

    }

    catch (System.ComponentModel.Win32Exception ex1)

    {

        result = "error";

        if (ex1.NativeErrorCode == ERROR_FILE_NOT_FOUND)

            result += ", " + ex1.Message;

    }

    catch (Exception ex2)

    {

        result = "error, " + ex2.Message;

    }

    return result;

}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Big Bear 的頭像
    Big Bear

    Programs Knowledge

    Big Bear 發表在 痞客邦 留言(0) 人氣()