简体   繁体   中英

Copying file from resources

Well In my C# project I add a .xml file to the resources, I want it to be extracted/copied from it to the application path, I was trying to doing this:

string appPath = Path.GetDirectoryName(Application.ExecutablePath);//Declaration of the apppath
File.Copy(appPath, Properties.Resources.config);//process for copy

But is not working :/, how can I do what I want?

Make sure the build action on your resource is set to "embed resource".

var assembly = Assembly.GetExecutingAssembly();
// See what resources are in the assembly (remove from the final code)
foreach (var name in assembly.GetManifestResourceNames()) {
    Console.Writeline("'{0}'", name);
}
using (var inputStream = assembly.GetManifestResourceStream(resourcePath)) {
    using( var outStream = File.OpenWrite(copyToPath)) {
        input.CopyTo(outStream);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM