By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,213 Members | 1,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,213 IT Pros & Developers. It's quick & easy.

How to include a file in a project

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"FrzzMan" <Fr***************@vnOCzone.com> wrote in message
news:e3**************@TK2MSFTNGP09.phx.gbl...
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

Nov 16 '05 #2

P: n/a
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

Ignacio Machin ( .NET/ C# MVP ) wrote:
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,

Nov 16 '05 #3

P: n/a
FrzzMan wrote:
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.

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

Ignacio Machin ( .NET/ C# MVP ) wrote:
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,

--
mikeb
Nov 16 '05 #4

P: n/a
There are some examples of embedding different file types into assemblies here ..

http://www.pocketnerd.net/Redirector...46-83D6A7E11EF

HT

RS
Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.