C# button extract embedded files
I am new to C# and working on an small application in Visual Studio. I ?have already added couple embedded files into my project. I did this after creating a folder in solution explorer and added the files into it. Now I want have a button, lets call it install or extract, to actually extract the files on to a users computer in a specified directory. I know i need to write some code after double clicking on the button, I am just not sure what to place in there. Any help / guidance will be appreciated.
Hemant SrivastavaPosted Nov 11, 2013, 2:24 PM
System.IO;
Adam SterPosted Nov 11, 2013, 2:07 PM
Hermant,
Thank you so much for your reply, I think I am a bit closer to my solution now.
I am letting the user choose the output directory via the browse button you can see below in the picture. Then I have an install button that will copy the files over. In the install button I believe I will type the code in. However, I am not sure what to define in the namespace, i.e: using system.io, using sytem.resources etc.? My folder is called "Test" and I have an embedded resource in it called "setup.exe"
Hemant SrivastavaPosted Nov 11, 2013, 1:35 PM
If this is the case, you can create a Button Click event handler and put a similar code like this;
private void btn_Extract_Click(object sender, EventArgs e)
{
string sourceDirectory = @"D:\temp\";
string destinationDirectory = @"D:\temp\Hemant\";
if (!Directory.Exists(destinationDirectory))
{
Directory.CreateDirectory(destinationDirectory);
}
// Copying the info.txt file from 'D:\temp\' to 'D:\temp\Hemant\'
File.Copy(sourceDirectory + "info.txt", destinationDirectory + "info.txt",true);
}
Note: Here your source folder would be your folder (what you see in the solution explorer)