我發現了一個檢查文件是否存在的好方法,如果它存在,請閱讀內容,但出於某種原因,我無法創建一個方法。用於檢查,讀取和返回文件內容的良好ASP.NET方法
這是我到目前爲止有:
<script runat="server">
void Page_Load(Object s, EventArgs e) {
lblFunction.Text = mwbInclude("test.txt");
}
string mwbInclude(string fileName) {
string inc = Server.MapPath("/extra/include/" + Request["game"] + "/" + fileName);
string valinc;
if(System.IO.File.Exists(inc))
{
valinc = System.IO.File.ReadAllText(inc);
}
return valinc;
}
</script>
我希望我能提供更多的信息,但是這是在服務器上沒有顯示錯誤的任何反饋,只需404頁。
將您的代碼包裝在try/catch中,並出現錯誤Response.Write異常信息 – 2010-01-19 00:15:38