title: WebAPI controller that handle json to write file
body: <p>I need to write a api restfull with asp.net that receive in the body a json like : </p>
  
  <pre><code>"{
      \"name\" : \"name of the file\",
      \"path\" : \"path of the file\",
      \"body\" : \"body of th file\"
  }"
  </code></pre>
  
  <p>and write a file in the server with the data from this json.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.IO;
  using System.Linq;
  using System.Threading.Tasks;
  using Microsoft.AspNetCore.Hosting.Server;
  using Microsoft.AspNetCore.Mvc;
  using Newtonsoft.Json;
  
  namespace tool_put.Controllers
  {
  
      [Route("api/[controller]")]
      [ApiController]
      public class ValuesController : ControllerBase
      {      
          [HttpPost]
          public String Post([FromBody] string value)
          {
              dynamic obj = JsonConvert.DeserializeObject(value);
              String path = obj.path + obj.name + ".txt";
              //StreamWriter Data = new StreamWriter(MapPath("~/"+path), (System.Text.Encoding)true);
              // Data.WriteLine(obj.body);
  
              return "true";
          }
      }
  }
  </code></pre>
  
  <p>I used visual studio on mac and when i run this on localhost and try to perform the http post from postman the file that wish didnt create.
  Note he comments because this solution with the StreamWriter object didnt work .
  How can solve this ?
  Is there any other method to write some text in a txt file on the server ?</p>