I'm coming to C# ASP.NET from Ruby and PHP, and I'm enjoying some elements of it but am finding certain things difficult to achieve. It's a bit different to get my head around, and I'd really appreciate it if someone could help me get this bit up and running.
I am trying to take some text sent in a POST request, HTML-escape it, and then write it to a text file.
So I look it up, read a little, and try:
<%
System.IO.StreamWriter file = new System.IO.StreamWriter(Server.MapPath(@"./messager.txt"));
file.WriteLine(Request.Form["message"]);
file.Close();
%>
Not doing the HTML-escaping yet, just trying to actually write to the text file.
This doesn't work, though; it throws no error that I can see, but just does nothing, the text file isn't written to at all. I've researched the methods and can't really figure out why. I would really love some help.
If it helps, here is working Ruby code for what I am trying to do:
File.open "messager.txt", "w" {|f| f.puts h params[:message]}
System.IO.File.ReadAllText(Server.MapPath(@"~\messager.txt"))does work so I don't think the path ist he problem.