Search code examples
javascriptc#c#-4.0file-iofilestream

How can i access a js file in my project?


I want to read "script1.js" by filestream in my console application like below. But it returns to me an error. Is there any better way to read a js file in application, by using filestream it returns to me error: FileNotFound exception.

enter image description here

enter image description here


Solution

  • As your FileReader is reading from your build destination not your project destination, it will not find the file (Look at that path it tires to read from, it is .\bin\Debug\script1.js, where your file will be at .\script1.js)

    The easiest fix is to change build action for your script file in its properties, and set Copy To Output Directory = Copy Always

    enter image description here