8
public UploadFile() 
{
    //File Data
    this.filePath = $("#inputFile").val();
    var file = $("#inputFile").get(0).files[0];  
    var reader = new FileReader();
    reader.onload = function (evt) {
    var fileContent = reader.result;
    var x = fileContent.bytes;                          
}

1 Answer 1

15

Your question isn't completely clear, but here's some sample code that may help. This should be valid TypeScript code, which reads a file from input element #inputFile and displays the text from it in a div with id #divMain.

$("#inputFile").on('change', null, (e) => {
    var input = <HTMLInputElement>e.target;
    var files = input.files;
    var f:File = files[0];
    var reader = new FileReader();
    var name = f.name;
    console.log("File name: " + name);
    reader.onload = function (e) {
        var target: any = e.target;
        var data = target.result;
        $("#divMain").text(data);
    };
    reader.readAsText(f);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.