得到这个错误,当我提交表单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