读取文本文件时的相对路径问题
技术科 2008-05-06 09:21:45 public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string[] filearr = File.ReadAllLines(Server.MapPath("~/") +"output.txt", Encoding.Default);
for (int i = 0; i < filearr.Length; i++)
{
// this.ListBox1.Items.Add(filearr[i]);
Response.Write(filearr[i]);
}
}
}
这段代码是读取与Defaultaspx.aspx在同一目录下的output.txt中的内容,但运行时提示:未能找到文件“E:\WebSite2\output.txt”。
请教这个相对路径如何设置