How to include a file in a project

  • Thread starter Thread starter FrzzMan
  • Start date Start date
F

FrzzMan

The subject may sound a lil dumb :D

But my problem is:

When my app run, it'll check if a specific file existed or not, if
existed it's OK, if not it will create default file. I want to hardcode
that file into my project and use it when needed.

Hope you understand my problem... I don't know how to explain well...

TIA
 
Hi,

Your post is confusing so I will get you a couple of scanarios and
solutions.

If you do not care if the file exist before run the first time, just create
it, when you run it again it will be already created
You can include this file ( or a copy of it ) in the project and mark it as
content, this will make it copied when u make a setup project.

you may use a config file to indicate where the file will be located, using
this form you can set where the file will be located, I have a similar
scenario than this, what I did was create the file in c:\temp in my machine
so it will always exist , then when I going to deploy it change the config
file to the location I need.

hope this help,
 
Sorry my English is not so good, it is not that I want to create a file
only.

What I want is to embed some content (in a file) with the app, and use
that content whenever I need without having to pack the content (in a
file) along with the setup.

For example, here's one of the screnario:

- I use an XML file to save user settings.
- When the app start, it should check if the file exist or not,
well-formed or not.
- If ok -> proceed as normal.
- If not ok -> delete current file, and create new file with default
content.
- That "default content" should be embeded into the executable file.

Hope you understand me, if not, just tell, I'll have my brother post
what I'm thinking :D His English much better than me :D
 
FrzzMan said:
Sorry my English is not so good, it is not that I want to create a file
only.

What I want is to embed some content (in a file) with the app, and use
that content whenever I need without having to pack the content (in a
file) along with the setup.

For example, here's one of the screnario:

- I use an XML file to save user settings.
- When the app start, it should check if the file exist or not,
well-formed or not.
- If ok -> proceed as normal.
- If not ok -> delete current file, and create new file with default
content.
- That "default content" should be embeded into the executable file.

If you are using VS.NET, include the file in your project and mark it as
an "Embedded Resource" in the Build Action property for that file. If
you're using the command line compilers, use the /resource switch to
include the file as a resource in the generated assembly. When you
build the assembly, the contents of the file will be copied into a
resource that's bound in the assembly.

Now use the Assembly.GetManifestResourceStream() method to read the file
from the assembly resource.

Do a search on the net for "GetManifestResourceStream" to get some examples.
 

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

Back
Top