Click here to Skip to main content
15,897,718 members
Home / Discussions / C#
   

C#

 
GeneralRe: am i dreaming Pin
imran_rafique1-Sep-02 12:50
imran_rafique1-Sep-02 12:50 
Generalwho to use it Pin
imran_rafique28-Aug-02 11:22
imran_rafique28-Aug-02 11:22 
GeneralPropertySheet Pin
Mazdak28-Aug-02 9:49
Mazdak28-Aug-02 9:49 
Generalpassing System.Guid into mediaSeek.SetTimeFormat Pin
Jarrett Vance28-Aug-02 8:51
Jarrett Vance28-Aug-02 8:51 
GeneralASP.NET question Pin
User 988528-Aug-02 5:16
User 988528-Aug-02 5:16 
GeneralInterop reference problem... Pin
Ryan Cromwell28-Aug-02 4:48
Ryan Cromwell28-Aug-02 4:48 
QuestionHow to read Embedded Resource in Assembly (File) ? Pin
Chris Richner28-Aug-02 3:15
Chris Richner28-Aug-02 3:15 
AnswerRe: How to read Embedded Resource in Assembly (File) ? Pin
James T. Johnson28-Aug-02 6:31
James T. Johnson28-Aug-02 6:31 
Step 1: Embedding a resource into your assembly

If you are using VS.NET simply add the text file to the project and in the properties for the file, set the Build Type to Embedded Resource.

If you are using the command line compiler add the following to your existing command line csc command.

/resource:mytextfile.txt,Name.You.Want.The.File.To.Have.In.The.Assembly.txt

Step 2: Getting a Stream object to your file

In Step 1 you either chose a name for the file or VS.NET created one for you. VS.NET names embedded files with this format: DefaultNamespace.Folder.Filename.ext if you just have the file sitting in the root of the project directory then it will just be DefaultNamespace.Filename.ext

First you need a reference to the Assembly object containing the file; this is usually done by getting a Type object for one of the classes in the assembly.

Assembly asm = typeof(MyClassInAssembly).Assembly;

Now that you have the assembly, you can get a Stream object for the file

Stream stream = asm.GetManifestResourceStream("name of my file in assembly");

Now that you have the stream you can do whatever you want with it; in your case you probably want to open up a FileStream and proceed to read the contents of stream and write them to the new FileStream.

HTH,

James
"And we are all men; apart from the females." - Colin Davies
GeneralImage field in database Pin
Mazdak28-Aug-02 3:05
Mazdak28-Aug-02 3:05 
GeneralRe: Image field in database Pin
Nnamdi Onyeyiri28-Aug-02 3:10
Nnamdi Onyeyiri28-Aug-02 3:10 
GeneralRe: Image field in database Pin
Mazdak28-Aug-02 3:14
Mazdak28-Aug-02 3:14 
GeneralRe: Image field in database Pin
Nnamdi Onyeyiri28-Aug-02 6:22
Nnamdi Onyeyiri28-Aug-02 6:22 
GeneralRe: Image field in database Pin
Mazdak28-Aug-02 6:43
Mazdak28-Aug-02 6:43 
GeneralRe: Image field in database Pin
Paul Riley28-Aug-02 3:18
Paul Riley28-Aug-02 3:18 
GeneralRe: Image field in database Pin
Mazdak28-Aug-02 3:45
Mazdak28-Aug-02 3:45 
GeneralRe: Image field in database Pin
Paul Riley28-Aug-02 3:58
Paul Riley28-Aug-02 3:58 
GeneralRe: Image field in database Pin
Mazdak28-Aug-02 5:51
Mazdak28-Aug-02 5:51 
GeneralRe: Image field in database Pin
Mazdak28-Aug-02 6:33
Mazdak28-Aug-02 6:33 
GeneralRe: Image field in database Pin
Paul Riley28-Aug-02 7:48
Paul Riley28-Aug-02 7:48 
GeneralRe: Image field in database Pin
Mazdak28-Aug-02 3:55
Mazdak28-Aug-02 3:55 
GeneralRe: Image field in database Pin
James T. Johnson28-Aug-02 6:21
James T. Johnson28-Aug-02 6:21 
GeneralRe: Image field in database Pin
Mazdak28-Aug-02 6:42
Mazdak28-Aug-02 6:42 
GeneralRe: Image field in database Pin
James T. Johnson28-Aug-02 6:54
James T. Johnson28-Aug-02 6:54 
GeneralRe: Image field in database Pin
leppie28-Aug-02 8:16
leppie28-Aug-02 8:16 
GeneralSound Library for C# Pin
leppie28-Aug-02 0:46
leppie28-Aug-02 0:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.