How can i access a js file in my project?

123 Views Asked by At

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

3

There are 3 best solutions below

0
On BEST ANSWER

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

1
On

Try to set the js file's "Generate Operation" property as "Resource" in your project, it will be copy to bin/Debug folder. Or you can copy it to the folder where the exe file is.

0
On

It seems your "script1.js" is NOT copied to the directory "Debug".

As one solution, you could mark the script1.js in Visual Studio, then go to "Properties" and then set these:

  • for "Build Action", choose "Content"
  • for "Copy to Output Directory", choose "Copy always"