currently I am trying to create two controller methods reading from file and writing to same file:
public ActionResult UploadText(string name)
{
var path = Path.Combine(Server.MapPath("~/text/"), name);
var fileContents = System.IO.File.ReadAllText(path);
ViewData["text"] = fileContents;
ViewData["textName"] = name;
return View();
}
[HttpPost]
public ActionResult TextPost(string textName)
{
string text = Request["text-content"];
var path = Path.Combine(Server.MapPath("~/text/"), textName);
System.IO.File.WriteAllText(path, text);
return RedirectToAction("Index");
}
Reading file content and writing to it works, but it cannot be read second time, File can't be accessed because it is being used by another process
error appears.
What am I doing wrong?