title: How do I write a text file from within a C# ASP.NET page?
body: <p>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.</p>
  
  <p>I am trying to take some text sent in a POST request, HTML-escape it, and then write it to a text file. </p>
  
  <p>So I look it up, read a little, and try:</p>
  
  <pre><code>&lt;% 
      System.IO.StreamWriter file = new System.IO.StreamWriter(Server.MapPath(@"./messager.txt"));
      file.WriteLine(Request.Form["message"]);
      file.Close();
  %&gt;
  </code></pre>
  
  <p>Not doing the HTML-escaping yet, just trying to actually write to the text file. </p>
  
  <p>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.</p>
  
  <p>If it helps, here is working Ruby code for what I am trying to do:</p>
  
  <pre><code>File.open "messager.txt", "w" {|f| f.puts h params[:message]}
  </code></pre>