1

How can we copy a content of text file from project file path to a string variable in javascript.

I used below code but it gives "Access Denied" error.

var sHTML = "";
var rawFile = new XMLHttpRequest();
rawFile.open("GET", "file://~/Templates/NewGridTemplate.txt", true);
      sHTML = rawFile.responseText;
phd
  • 69,888
  • 11
  • 97
  • 133
Keval Raj
  • 39
  • 2
  • 10
  • This might help https://stackoverflow.com/questions/13709482/how-to-read-text-file-in-javascript – lit Jul 08 '17 at 16:14

1 Answers1

0

Read the html template in C# code and then send it to your html code and assign to innerHTML

   using (StreamReader sr = new StreamReader(@"D:\Template.html")){
   // Read the stream to a string, and write the string to the console.
   obj.svar = sr.ReadToEnd().Replace(Environment.NewLine, " ");
   //Console.WriteLine(line);
   }
Keval Raj
  • 39
  • 2
  • 10