得到這個錯誤,當我提交表單savetext.aspx操作文件:CS0120:一個對象引用必須
Compiler Error Message: CS0120: An object reference is required for the nonstatic field, method, or property 'System.Web.UI.Page.Request.get'
在此行中:
string path = "/txtfiles/" + Request.Form["file_name"];
整個代碼:
<%@ Page Language="C#" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
class Test
{
public static void Main()
{
string path = "/txtfiles/" + Request.Form["file_name"];
if (!File.Exists(path))
{
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine(request.form["seatsArray"]);
sw.WriteLine("");
}
}
using (StreamReader sr = File.OpenText(path))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
}
}
</script>
我該如何解決?
謝謝!
'公共靜態無效Main()'在一個ASPX頁?!嗯...也許你應該解釋一下你正在嘗試做什麼,因爲我感覺到這個部隊的干擾。 – 2010-07-14 14:50:14
難道你不需要 <%@ Import Namespace =「System.Web.UI.Page」%> – MikeTWebb 2010-07-14 14:51:17
@MikeTWebb,不,他不會。 – 2010-07-14 14:52:21