Groups | Blog | Home
all groups > c# > april 2004 >

c# : How to include a file in a project


mikeb
4/19/2004 12:45:26 PM
[quoted text, click to view]

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.

[quoted text, click to view]


--
Ignacio Machin ( .NET/ C# MVP )
4/19/2004 1:36:04 PM
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

[quoted text, click to view]

PocketNerd
4/19/2004 1:51:03 PM
There are some examples of embedding different file types into assemblies here ..

http://www.pocketnerd.net/Redirector.aspx?documentID=60E3428E-3852-49CE-8846-83D6A7E11EF

HT

FrzzMan
4/19/2004 11:29:23 PM
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...

FrzzMan
4/20/2004 2:26:07 AM
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

[quoted text, click to view]
AddThis Social Bookmark Button