Writing file to web server - ASP.NET

后端 未结 4 1559
走了就别回头了
走了就别回头了 2020-11-30 01:33

I simply want to write the contents of a TextBox control to a file in the root of the web server directory... how do I specify it?

Bear in mind, I\'m testing this lo

4条回答
  •  盖世英雄少女心
    2020-11-30 02:30

    protected void TestSubmit_ServerClick(object sender, EventArgs e)
    {
      using (StreamWriter _testData = new StreamWriter(Server.MapPath("~/data.txt"), true))
     {
      _testData.WriteLine(TextBox1.Text); // Write the file.
     }         
    }
    

    Server.MapPath takes a virtual path and returns an absolute one. "~" is used to resolve to the application root.

提交回复
热议问题