I added image to my solution. Changed compilation action property to resource and don't copy. Application in first run check is directories and files are existing if not they are created. My application needs default image of object. So thats why I added image to solution. Now how I can copy it to specific disk location.
I written this from samples which I founded.
if (!File.Exists(path_exe + "\\images\\drinks\\defaultIMG.jpg"))
{
using (var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream("Data\\defaultIMG.jpg"))
{
using (var file = new FileStream(path_exe + "\\images\\drinks\\defaultIMG.jpg", FileMode.Create, FileAccess.Write))
{
resource.CopyTo(file);
}
}
}
But this creates only empty file.
I Think the easiest way is:
Properties.Resources.defaultIMG.Save(path_exe + "\\images\\drinks\\defaultIMG.jpg");
Where defaultIMG is your Image resource name.
I found sample of code on http://www.c-sharpcorner.com/uploadfile/40e97e/saving-an-embedded-file-in-C-Sharp/ It works good
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Zeszycik.Data.defaultIMG.jpg");
FileStream fileStream = new FileStream("new.jpg", FileMode.CreateNew);
for (int i = 0; i < stream.Length; i++)
fileStream.WriteByte((byte)stream.ReadByte());
fileStream.Close();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With