[Implement] Start/Copy File

[Implement] Start File

Start File:


{
    string result = "success";

    string filePath = System.IO.Path.GetDirectoryName(
        System.Windows.Forms.Application.ExecutablePath);

    const int ERROR_FILE_NOT_FOUND = 2;
    System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
    try
    {
        myProcess.StartInfo.FileName = fileName;
        myProcess.StartInfo.WorkingDirectory = filePath;
        myProcess.StartInfo.Verb = "Open";
        myProcess.StartInfo.CreateNoWindow = true;  //設置不顯示窗口
        myProcess.StartInfo.UseShellExecute = false;        //關閉Shell的使用
        myProcess.StartInfo.RedirectStandardInput = true;   //重定向標準輸入
        myProcess.StartInfo.RedirectStandardOutput = true;  //重定向標準輸出
        myProcess.StartInfo.RedirectStandardError = true;   //重定向錯誤輸出
        //p.StartInfo.Arguments = "/c " + "cd " + System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\";    //設定程式執行參數
        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;
}

Create Directory:


if(!System.IO.Directory.Exists(path));
{
    System.IO.Directory.CreateDirectory(Path);
}

Create File:


if (!System.IO.File.Exists(path ))
 {
    using (System.IO.FileStream fs = System.IO.File.Create(path)) //create file
        fs.Close();//release resource
}

Copy File (Local to Local ):


System.IO.File.Copy(@"C:\abc.txt", @"D:\def.txt", true);

Copy File (Local to Server ):

http://www.dotblogs.com.tw/brian/archive/2012/10/19/77671.aspx