Skip to content

Instantly share code, notes, and snippets.

@mikebrind
Created September 2, 2016 13:12
Show Gist options
  • Save mikebrind/e42dca7e3cded9990c20627a7ca9e9f7 to your computer and use it in GitHub Desktop.
Save mikebrind/e42dca7e3cded9990c20627a7ca9e9f7 to your computer and use it in GitHub Desktop.
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
namespace IHostingEnvironmentExample.Controllers
{
public class HomeController : Controller
{
private IHostingEnvironment _env;
public HomeController(IHostingEnvironment env)
{
_env = env;
}
public IActionResult Index()
{
var webRoot = _env.WebRootPath;
var file = System.IO.Path.Combine(webRoot, "test.txt");
System.IO.File.WriteAllText(file, "Hello World!");
return View();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment