Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

(c#) Extract (copy) MyFile.exe file from Resources to disc (E partition)

$
0
0

Hello everyone,
I am trying to extract (copy/paste) MyFile.exe from the Resource of my project.
I have added "MyFile.exe" to my Resource of my project (myProject/Properties/Resources/Add Resource/ Add Existing File..)
I want to click this button to extract (copy/paste) "MyFile.exe" file from Resources to the E partition. 
Please help. Thanks.

I've used the following code, but it doesn't work (Microsoft .NET Framework 4.0 Client Profile):

public void ExtractFileFromResources(String filename, String location)
        {
            //  Assembly assembly = Assembly.GetExecutingAssembly();
            System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
            Stream resFilestream = a.GetManifestResourceStream(filename);
            if (resFilestream != null)
            {
                BinaryReader br = new BinaryReader(resFilestream);
                FileStream fs = new FileStream(location, FileMode.Create);
                BinaryWriter bw = new BinaryWriter(fs);
                byte[] ba = new byte[resFilestream.Length];
                resFilestream.Read(ba, 0, ba.Length);
                bw.Write(ba);
                br.Close();
                bw.Close();
                resFilestream.Close();
            }
        }

private void Extract()
        {
            ExtractFileFromResources("MyFile.exe", @"E:\MyFile.exe");          
        }


Viewing all articles
Browse latest Browse all 8156

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>