title: ASP .NET Core write to XML-file
body: <p>In ASP .NET Core, I am trying to add some XML-Element with attributes to an existing XML file.</p>
  
  <p>In ASP NET 4.5, I would have used the code below to make this working:</p>
  
  <pre><code>string path = Server.MapPath("~/Data/foo.xml");
  XDocument xdoc = XDocument.Load(path);
     //Do stuff with XElement and XAttributes...
  xdoc.Save(path);
  </code></pre>
  
  <p>But with ASP .NET Core, I cannot use Server.MapPath(), So I get the complete path with IHostingEnvironment instead: (Read more <a href="http://www.mikesdotnetting.com/article/302/server-mappath-equivalent-in-asp-net-core" rel="noreferrer">here</a> )</p>
  
  <p>Running the complete code below on ASP .NET Core will result in "Cannot convert from String to System.IO.Stream" when trying to run "xdoc.Save(pathToDataFile);" ??</p>
  
  <pre><code>  var contentRoot = hostingEnvironment.ContentRootPath;
    string pathToDataFile = contentRoot + "\\Data\\foo.xml";
    XDocument xdoc = XDocument.Load(pathToDataFile);
      //Do stuff with XElement and XAttributes...
    xdoc.Save(pathToDataFile);
  </code></pre>
  
  <p>Why is "xdoc.Save()" not working in ASP .NET Core but working fine in .NET 4.5?</p>