当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Read input stream of file before uploading to server - ASP.NET

问题描述:

This question already has an answer here:

  • File Upload read to memory and use as text file - is there a better way?

    3 answers

网友答案:

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>
分享给朋友:
您可能感兴趣的文章:
随机阅读: