Click here to Skip to main content
15,891,813 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've added my file into resources with right click -> existing item. Now I want to copy the added file into another directory like this:

C#
File.Copy(@"I don't know", @"C:\Users\user-1\Desktop\", true);


I don't know what I have to write in @"I don't know" part to addressing the added resource file.

What I have tried:

C#
File.Copy(@"I don't know", @"C:\Users\user-1\Desktop\", true);
Posted
Updated 30-Mar-17 18:16pm
v3

1 solution

You can't use File methods to get at a resource. You should be using Assembly.GetManifestResourceStream. You can then just write the content, be it text or bytes, to the target file yourself.

GetManifestResourceStream[^]
 
Share this answer
 
Comments
[no name] 31-Mar-17 6:39am    
I understood that I have to use the System.Reflection library and use the "GetManifestResourceStream(String)". But I don't know how can I copy the file like that
Dave Kreskowiak 31-Mar-17 8:48am    
You don't COPY the file. GetManifestResourceStream returns a Stream object. You open the destination file you want to "copy" the content to, read the bytes from the resource Stream, write them to the file stream you opened, then close both streams. Done!
[no name] 31-Mar-17 19:32pm    
Can you please give me an example about it?
I did search about it, but I can't understand :/
Dave Kreskowiak 31-Mar-17 21:30pm    
Your Google-Fu needs some serious work. Google for "Copy resource stream to disk c#[^]" and you'll find tons of examples.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900