cancel
Showing results for 
Search instead for 
Did you mean: 

Read Text file using Java Script

mohamed_dbouk
Discoverer
0 Kudos

Hi,

I am trying to read a text file using Java Script within the webroot of MII as .HTML file. I have provided the path as below but where I am not able to open the file. Any clue to provide the relative path or any changes required on the below path ?

var FileOpener = new ActiveXObject("Scripting.FileSystemObject");

var FilePointer = FileOpener.OpenTextFile("E:\\usr\\sap\\MID\\J00\\j2ee\\cluster\\apps\\sap.com\\xapps~xmii~ear\\servlet_jsp\\XMII\\root\\CM\\OCTAL\\TestTV\\Test.txt", 1, true);

FileContents = FilePointer.ReadAll(); // we can use FilePointer.ReadAll() to read all the lines

The Error Log shows as :

Path not found

Regards,

Mohamed

Accepted Solutions (0)

Answers (1)

Answers (1)

Private_Member_14935
Active Participant
0 Kudos

Hi Mohamed,

If you have the text file within webroot of MII, then you can think of using jQuery.get() for reading the content of the file.

You could try the below piece of code:

$.get( "http://<server>:<port>/XMII/CM/Default/Test.txt", function( data ) {

  $( ".result" ).html(data);

  alert(data);// The file content is available in this variable "data"

  });

Hope this helps!

Regards,

Ria

mohamed_dbouk
Discoverer
0 Kudos

Hi Ria,

Thanks for your reply.

I have added the code as above but its not recognising the $. Do you need to include any files?

Error Throws as :-

'$' is undefined

Code as below:-

<html>
<head>
<script language="javascript">
function Read()
{

$.get( "http://ops20mi1.nat.pet:50000/XMII/CM/Test/PP/Sheet/Dashboard/Television/Test.txt", function( data ) {
  $(".result").html(data);
  alert(data);
// The file content is available in this variable "data"
  });

}
</script></head><body onLoad="Read()"></body></html>

Private_Member_14935
Active Participant
0 Kudos

Hi Mohamed,

Sorry, I missed to mention that you would have to include jquery javascript library for using the jQuery.get().

You can download it from http://jquery.com/download/

Do let me know if you need more information.

Also I would like to know the version of MII you are using.

Regards,

Ria

Former Member
0 Kudos

Hi Mohamed,

I tried above code after importing JQuery Library through script Tag. It worked for me . Pls check.

Note : You can place Jquery1.xx.xx.js file in the same folder where you saved this IRPT/HTML file.

<HTML>

<HEAD>

    <TITLE>Your Title Here</TITLE>

    <SCRIPT type="text/javascript" src="jquery-1.9.1.js"></SCRIPT>

    <script language="javascript">

function Read()

{

$.get( "http://ldcimfb.wdf.sap.corp:50100/XMII/CM/Regression_15.0/CrossTab.txt", function( data ) {

  $(".result").html(data);

  alert(data);

// The file content is available in this variable "data"

  });

}

</script>

</HEAD>

<BODY onLoad="Read()">

</BODY>

</HTML>