adding files at compile time

D

DBC User

I have a situation, where I need to add 4 or 5 data files (they change
every time I build) in my project during build time and somehow I need
a way to access these files during runtime.
So I have 2 questions
1. Is it possible to identify all the files in the resource file
during runtime by name of the file?
2. Is it possible to add files to a project at build time to make an
exe with those files?
Thanks.
 
R

RobinS

You can add them to your project, set Build Action to "Content" and the
"Copy to Output Dir" to "Copy Always". Then you can load it by its relative
path to the ApplicationPath.

Or you can add them as an embedded resource.

Is that what you mean? You just want to include them and then access them?

RobinS.
GoldMail, Inc.
 
D

DBC User

You can add them to your project, set Build Action to "Content" and the
"Copy to Output Dir" to "Copy Always". Then you can load it by its relative
path to the ApplicationPath.

Or you can add them as an embedded resource.

Is that what you mean? You just want to include them and then access them?

RobinS.
GoldMail, Inc.





- Show quoted text -

I would like to add them as embedded resource. This is what I found so
far, I could write a seperate program which will generate the resource
file with all the required files and then build the new program which
need to access it with the new resource. So I would like to find a way
to add the text files to resource file and way to read it back.
Thanks.
 
F

Family Tree Mike

DBC User said:
I would like to add them as embedded resource. This is what I found so
far, I could write a seperate program which will generate the resource
file with all the required files and then build the new program which
need to access it with the new resource. So I would like to find a way
to add the text files to resource file and way to read it back.
Thanks.

Then set the "Build Action" to "Embedded Resource". Do you mean the
filenames change every build or the file contents change every build?
 
D

DBC User

Then set the "Build Action" to "Embedded Resource".  Do you mean the
filenames change every build or the file contents change every build?  
Yes that is correct. So here is what I am planning to do
1. All the input files required will be staged in a temp folder for
me. So I will have one program which will read each file and create a
console c# program to add it to a resource file. This step only
creates an output c# program.
2. Now I run command line compiler to build and then run the program.
The output will be a resource file.
3. Now build my actual program which expects all the files in resource
file to run at the destination with the resource file created at step
2.
4. Copy the final exe to destination server and run it.

I got al step 2, 3 and 4 except the part where how to add a file to a
resource file and read a file from resource file. All the example I
have seen so far are image files. I couldn't find single example for
adding a text/binary file to a resource file.

So if someone can help me on how to write a text file to resource file
and read the text file back from resource file, it would be greatful.

Thanks again.
 
F

Family Tree Mike

DBC User said:
Yes that is correct. So here is what I am planning to do
1. All the input files required will be staged in a temp folder for
me. So I will have one program which will read each file and create a
console c# program to add it to a resource file. This step only
creates an output c# program.
2. Now I run command line compiler to build and then run the program.
The output will be a resource file.
3. Now build my actual program which expects all the files in resource
file to run at the destination with the resource file created at step
2.
4. Copy the final exe to destination server and run it.

I got al step 2, 3 and 4 except the part where how to add a file to a
resource file and read a file from resource file. All the example I
have seen so far are image files. I couldn't find single example for
adding a text/binary file to a resource file.

So if someone can help me on how to write a text file to resource file
and read the text file back from resource file, it would be greatful.

Thanks again.

The process for adding the files as a resource should be the same whether
the file is a bitmap/jpeg/tiff or the text of "War and Peace". You get the
files out at runtime with GetManifestResourceStream and read it with a
StreamReader, rather than sending it to the constructor for an image.
 

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