I'm working on a Javascript compiler, first of all I want to load the text.txt by opening a File Dialog and load this into my Textbox. I've found some documentation on the internet how to achieve this but most of these contents teaches you by saving the file into your server. I'm looking how to just load the text file and paste or show into a Textbox.
This is my code which I have achieved so far:
Model
public class CargarArchivo
{
public string file { get; set; }
}
Controller
[HttpPost]
public ActionResult Index( HttpPostedFileBase File)
{
CargarArchivo archivo = new CargarArchivo();
return View(archivo);
}
View
@using (Html.BeginForm())
{
@Html.EditorFor(model => model.file, new { htmlAttributes = new { @class = "form-control", @type = "file" } })
<input type="submit" value="upload" class="btn btn-primary" />
}
I have no idea what is HttpPostedFileBase
for, I just followed this on the documentation. Code works OK and just open a file dialog.
I have tried this, but didn't work:
[HttpPost]
public ActionResult Index( string File)
{
var cont = System.IO.File.ReadAllText(File);
CargarArchivo archivo = new CargarArchivo();
archivo.File = cont;
return View(archivo);
}