Howto: Include text data in a .net executable?

O

Ola Theander

Dear subscribers



I'm currently creating a small application that will run at the end of a web
installation to configure a SQL Server. For this task I have a SQL batch
file in the same format as SQL Query Analyzer uses. I would prefer not to
merge the content of this file into the source code of configuration
application but instead keep the SQL commands in a text file included in the
executable, pretty much like resource data, for easy updates in the future.



My question is, what is the best way to attach text data to an .net
executable and still be able to extract it when the application is running?
What I want is to be able to do is to get the text data pretty much the same
way as if it was in a separate text file but with the difference that the
data is actually included in the executable.



Any help with this matter would be greatly appreciated.



Kind regards, Ola Theander
 
K

Kirby Turner

I would include the file as an embedded resource in the assembly and
load the contents in as a stream at runtime. Get a reference to the
assembly containing the embedded resource and use the method
..GetManifestResourceStream() found on the Assembly class. Once you
have the resource as a stream, you can do as you please with the
content.

-KIRBY
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top