views:

41

answers:

1

i m devlopuing one consol application in c#.net and in this i need one text file which is resides in local disc but i wanna make it dynamic and add that file in the project as a resources so when i create final exe of my project and place it any where it works proparly without having that file in local disc.

pls help me regarding this issue

and describe this in detail because i m new with this framwork and consol applocation too.

A: 

You can embed the text file as a resource into the executable and then get it as a stream when running. Add the file to your project and change "Build Action" to "Embedded Resource".

Then, to get the resource when running:

Assembly assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream("Namespace.filename.txt");

Especially note the Namespace part of the resource stream name, that is the namespace of the project folder where you added the file. It will then be appended with the actual filename, including suffix.

Anders Abel