0

I have a text file which is located in a particular folder nn the server. The folder location is stored in the web.config.

I am able to get the value of the folder location in jquery but I am able to read the txt file:

Below is my code:

var baseUrl = window.location.origin;
var fileName = baseUrl + "/" + fileLocation.split("/").pop() + "/" + evt.currentTarget.id;
jQuery.get(fileName, function (data) {
            $("#pdfviewerJs").html(data.replace('n', ''));
        });

The evt.currentTarget.id is the name of the file and the pdfviewerJs is just a div to display content of text file. Somehow this is not working. The fileName is as below:

http://localhost:58003//D://ViewerTest//test_1240560034094.txt

Any help pls..? I just need to get the file and display the content of the txt.

11
  • Possible duplicate of How do I read a text file on my local disk into a variable in javascript Commented May 3, 2019 at 6:56
  • @Diar selimi the question clearly says the file is located on the server Commented May 3, 2019 at 8:06
  • 2
    Tabby you need to provide a URL to the file, not a disk path. The browser cannot see the server's filesystem Commented May 3, 2019 at 8:06
  • What do you mean by "Somehow this is not working"? What happens instead? What have you tried to debug this problem? Commented May 3, 2019 at 8:44
  • @ADyson: But then I really can't read the txt file using javascript? Commented May 6, 2019 at 9:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.