Question is rather simple, and somewhat pointless I understand, but still…
Database is on the server, of course, and I need an action that will when initiated grab that file from database and save it to a folder that is in my AppSettings["Active"] configuration property.
Basically,
public ActionResult Activate(int id)
{
Project project = db.Projects.Find(id);
var activeProjectData = project.XML; // project.XML returns byte[] type
//For download (not in this method of course) i'm using something like return File(activeProjectData, "text/xml"); and that works ok
}
Now I want to save that file to AppSettings["Active"] path. Not to sure how to go about it. I’ve tried using System.IO.File.Create() but that didn’t quite turn out well.
Any help is appreciated.
Simply create a FileStream and use it to write the data:
If you don’t need more control than that, there is a simple helper method on the
Fileclass: