Click here to Skip to main content
15,885,910 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to upload a file like .txt and i want to get the data from it and store in array and do some logoc in that by using java script
my snippet is
function m1(file,target) {
      var file = document.getElementById("fup1").value;

      var input= file.trim().replace(';', ',').split(',');
       var distinctArray = input.filter(function (val) {
           return input.indexOf(val) == -1;
           });
      target.value = distinctArray.join(',');
  }


and my controls are
JavaScript
<table>
   <tr>
   <td> <asp:FileUpload ID="fup1" runat="server" /></td>
   <td><asp:TextBox ID="txt1" runat="server" TextMode="MultiLine"></asp:TextBox></td>
   <td><input type="button" id="btn1" value="Submit" onclick='m1(<%=fup1.ClientID%>,<%=txt1.ClientID%>);return false;' /></td>
   </tr>
   </table>

Here i dont get any thing

please help me...thanks in advance
Posted
Updated 26-Jan-15 20:20pm
v3

1 solution

Reading the uploaded file isn't that simple unfortunatly.
The value of the file control will just be the file name.

You'll need access to the actual stream. In HTML4 the only way to do this was to post a form containing the file input to the server and let the server read the file.

Luckily HTML5 gives you way's to read the file through javascript. But it isn't as easy a you hoped. Please read;

http://www.html5rocks.com/en/tutorials/file/dndfiles/[^]

And I believe this blog post reads a textfile like you need;

http://stackoverflow.com/questions/3146483/html5-file-api-read-as-text-and-binary/3146509#3146509[^]

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900