fh = fopen('c:\\FileName.txt', 0); // Open the file for reading.
if(fh!=-1) // Check if the file has been successfully opened.
{
length = flength(fh); // Get the length of the file.
str = fread(fh, length); // Read in the entire file.
fclose(fh); // Close the file.
// Display the contents of the file.
write(str);
}
With javascripts, it's not possible to do file IO operations. If it's possible to do with javascripts, there would be a major security breach for web applications.
mj_developer
Member
174 Points
410 Posts
Reading the contents of a text file using JavaScript
Dec 28, 2012 07:34 PM|LINK
How can I read the contents of a text file using JavaScript?
jprochazka
Contributor
4812 Points
733 Posts
Re: Reading the contents of a text file using JavaScript
Dec 28, 2012 07:49 PM|LINK
http://www.c-point.com/JavaScript/articles/file_access_with_JavaScript.htm
fh = fopen('c:\\FileName.txt', 0); // Open the file for reading. if(fh!=-1) // Check if the file has been successfully opened. { length = flength(fh); // Get the length of the file. str = fread(fh, length); // Read in the entire file. fclose(fh); // Close the file. // Display the contents of the file. write(str); }A1ien51
All-Star
29935 Points
5821 Posts
Re: Reading the contents of a text file using JavaScript
Dec 28, 2012 07:51 PM|LINK
How many places are you going to ask this question? Spend some time and give details on your question. LIke where the file lives. Yikes.
mj_developer
Member
174 Points
410 Posts
Re: Reading the contents of a text file using JavaScript
Dec 29, 2012 04:55 AM|LINK
@jprochazka, I'm getting the following error message:
the value of the property 'fopen' is null or undefined, not a Function object.
What is the problem?
Ruchira
All-Star
42882 Points
7018 Posts
MVP
Re: Reading the contents of a text file using JavaScript
Dec 29, 2012 06:18 AM|LINK
Hello,
With javascripts, it's not possible to do file IO operations. If it's possible to do with javascripts, there would be a major security breach for web applications.
You have to use a technology like silverlight.
http://progproblems.blogspot.com/2009/11/saveread-file-from-silverlight-30-in.html
For more about this, I suggest you to post your question on the silverlight forums if you decide to do it with silverlight.
My Tech blog | TwitterPlease 'Mark as Answer' if this post helps you.roopeshreddy
All-Star
20119 Points
3320 Posts
Re: Reading the contents of a text file using JavaScript
Dec 30, 2012 02:59 PM|LINK
Hi,
With JavaScript it's not possible, but HTML 5 has got few FileSystem API's which made reading of file in Client System possible!
http://www.html5rocks.com/en/tutorials/file/filesystem/
NOTE: Works in HTML 5 compatible browsers!
Hope it helps u...
Roopesh Reddy C
Roopesh's Space
Anil Srivast...
Member
442 Points
292 Posts
Re: Reading the contents of a text file using JavaScript
Dec 30, 2012 03:59 PM|LINK
use System.IO namespace
if u r using character != -1
if using string != null
Javascript should never ever be used
http://www.csharp-examples.net/filestream-open-file/
http://www.eggheadcafe.com/community/csharp/2/10046526/how-to-read-word-doc-using-filestream-and-streamreader-class.aspx