我尝试打开文件并更新文件中的内容,它会得到像这样的总和错误。
我的代码
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Request.QueryString("log") = "no" Then
pinfo.Text = "Invalid Username / Password"
End If
Session.Clear()
Dim FileWriter As StreamWriter
Dim FileReader As StreamReader
Dim Countstr As String
FileReader = File.OpenText("/dmkg/Counter.txt")
Countstr = FileReader.ReadLine
FileReader.Close()
Countstr = Countstr + 700
FileWriter = File.CreateText("/dmkg/Counter.txt")
FileWriter.WriteLine(Countstr)
FileWriter.Close()
End Sub
检查代码并告诉我哪里出错了。
答案 0 :(得分:1)
您必须在OpenText方法而不是文件名
中传递正确的PATH<强>例如强>
Dim path As String = "c:\temp\MyTest.txt"
FileReader = File.OpenText(path)
所以请确保您的文件路径正确。
如果它存储在服务器中,那么您需要使用Server.Mappath()
FileReader = File.OpenText(Server.MapPath("/dmkg/Counter.txt"))
启用访问权限
授予对路径的ASP.NET写访问权,