close

該程式片段主要是<判斷檔案路徑是否有檔案,有就window.open,如沒有則轉到錯誤頁面處理>。

string url = "\\\\report\\\\exp_year_report_" + strYear + ".html";

string path = Server.MapPath("~") + url;
bool result = System.IO.File.Exists(path);//使用絕對路徑
if (result)
{
        //使用相對路徑
        ScriptManager.RegisterStartupScript(Page, GetType(), "ALERT", "window.open('" + url + "','_middle','menubar=no,status=no,scrollbars=yes,toolbar=no');", true);
        }
        else
        {
        string msg = "無資料(" + path + "),如有需要,請資訊單位協助。謝謝!";
        ScriptManager.RegisterStartupScript(Page, GetType(), "ALERT", "window.open('ErrorMessagePage.aspx?err_msg=" + msg + "','_middle','menubar=no,status=no,scrollbars=yes,toolbar=no');", true);
        }

}

 

以上程式有幾個技術重點分析:

1、System.IO.File.Exists(path);//使用絕對路徑:檔案存在的判斷語法,一定要引用<using System.Text>。

2、ScriptManager.RegisterStartupScript(Page, GetType(), "ALERT", "window.open('" + url + "','_middle','menubar=no,status=no,scrollbars=yes,toolbar=no');", true):

      Script語法,開啟window open,這裡url為資料夾之相對路徑。

3、string path = Server.MapPath("~") + url:絕對路徑的語法。

arrow
arrow
    全站熱搜

    Anson Chiang 發表在 痞客邦 留言(0) 人氣()