tags:

views:

130

answers:

3

Is there a way I can open and read a text file within a .NET project? I know I can use the System.IO.StreamReader class to do it for a Windows text file.

I'd like to store some SQL scripts for upgrading my database in text files within my project. Since I'm writing this in VB I can't just paste the scripts directly into my code due to line continuations, where I could if it were C#. These are very long scripts.

+3  A: 

Text files inside a project are not added to your executable. You can enable Copy to Output Directory in the properties for the .sql file. This will copy them alongside your assemblies to the bin directory.

From there, your program could read them like any other file.

Andomar
+1  A: 

Embed as resources in the assembly, then use ResourceManager to read them into a Stream or String at runtime?

Richard
A: 

You can use embedded resources and use a StreamReader on the stream returned by Assembly.GetManifestResourceStream to read those.

Lucero