There are several ways to deal with this, but there is a fundamental understanding that you must first collect. Issuing something like @"Queries/..." is not going to do on its own. You need to use the System.IO namespace to perform I / O.
With that part of the foundation, albeit a little more, when you issue a command like this:
File.ReadAllText("firstSqlQuery.sql");
the path that is implied is the Working Directory assembly that runs the code. When debugging an application in Visual Studio, especially an ASP.NET application, the bin directory, which is located in the project directory, is by default . So, if you want to access the Queries folder, you will need to do something like this:
File.ReadAllText(@"..\Queries\firstSqlQuery.sql");
so that is one way of processing it.
Another way to process this file would be to copy the file to the bin folder each time the project is built, if you look at the properties of the file (for example, create a Post Build Event ), but this works more than I think you're looking for.
Again, the key here is to understand which directory you are starting with.
Finally, it is worth noting that if you use the directory structure, you need to make sure that the Queries folder is deployed to the real site. This probably goes without saying, but I have seen people come across this exact problem before.
source share