0

I want to read the input stream of a file before it starts uploading to the server. This is the way I get the input stream.

 FileUpload1.PostedFile.InputStream

But this method executes after the file has uploaded.I see in the buttom left corner an upload progress. Is it possible to read the bytes of the file before the upload starts ?

Ngine
  • 65
  • 8

1 Answers1

0

there is an example how you could read file in browser and examine its content using javascript qoute from: open file using js

 function readSingleFile(e) {
  var file = e.target.files[0];
  if (!file) {
    return;
  }
  var reader = new FileReader();
  reader.onload = function(e) {
    var contents = e.target.result;
    displayContents(contents);
  };
  reader.readAsText(file);
}

function displayContents(contents) {
  var element = document.getElementById('file-content');
  element.innerHTML = contents;
}

document.getElementById('file-input')
  .addEventListener('change', readSingleFile, false);

And in html you could have

<input type="file" id="file-input" />
<h3>Contents of the file:</h3>
<pre id="file-content"></pre>
Community
  • 1
  • 1
profesor79
  • 9,213
  • 3
  • 31
  • 52