Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have asked a question here before and i have got a solution too. This is the link of my question- http://www.codeproject.com/Questions/613427/How-to-a-copy-text-file-without-overwrite-existing?arn=0

problem is i want to do same thing but using embedded text file as source file and i have try to solve it but no success. Plz help.
Posted
Comments
[no name] 20-Jun-14 15:29pm    
http://stackoverflow.com/questions/13031778/how-can-i-extract-a-file-from-an-embedded-resource-and-save-it-to-disk
Pankaj Mahor 20-Jun-14 15:49pm    
I have already check it but still no success. I cant undestand what i should write in place of source file path because the file is embedded?

use the following code:


C#
private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var resourceName = "WindowsFormsApplication1.TextFile1.txt";
                WriteResourceToFile(resourceName, "C:\\1.txt");
            }
            catch
            {
                MessageBox.Show("Error accessing resources!");
            }
        }

        public void WriteResourceToFile(string resourceName, string fileName)
        {
            using (var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
            {
                using (var file = new FileStream(fileName, FileMode.Create, FileAccess.Write))
                {
                    resource.CopyTo(file);
                }
            }
        }


and also you can find a good explanation in the following links :

http://stackoverflow.com/questions/13031778/how-can-i-extract-a-file-from-an-embedded-resource-and-save-it-to-disk[^]

the Embedded resource name is "YourNamespace.ResourceName.Extension" which is explaind perfectly here
http://support.microsoft.com/kb/319292[^]
 
Share this answer
 
This m$ article[^] shows you how to access the embedded text file using StreamReader.

this m$ article[^] shows you how to write the contents of the StreamReader to a file
 
Share this answer
 

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