Reputation: 1113
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?
Upvotes: 2
Views: 4305
Reputation: 726629
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);
}
}
Upvotes: 6