Last post Oct 19, 2009 06:10 PM by netproblems
Oct 19, 2009 03:35 PM|netproblems|LINK
In the following, Response.Write poduces the expected result of displaying user name and password - but nthing is written to the text file (colocated in the root directory). Any thoughts on what I am doing wrong?
Partial Class getCustomer
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim Username As String
Username = txtUsername.Text & "<br />"
Username = Username & txtPassword.Text
' Create an instance of StreamWriter to write text to a file.
Dim sw As StreamWriter = New StreamWriter("GetCustomer.txt")
' Add user name to the file.
' Add password to the file.
Oct 19, 2009 04:53 PM|DavidKiff|LINK
That should work. You could try calling sw.Flush to ensure its pushed out, however I thought close also did that. Do you have permission to save in the root? Its probably better to save within the App_Data folder, and set relevant permissions on it.
Oct 19, 2009 06:10 PM|netproblems|LINK
Well, I found that I coud write into something like c:Getcustomer.txt - but writing to the file within the site seemd to be a problem no matter what I did. Trying the App_Data folder, the server could not find the file. But your reply gave me an idea,
and the following cracked it:
Dim fileName As String = Server.MapPath("~/App_Data/GetCustomer.txt")
Dim sw As StreamWriter = New StreamWriter(fileName)