This question has already been answered:

In general, there is textBox1 and the bud in textBox1 should write the folder directory, in my case C: \ Users \ 1 \ Desktop \ 123, and when you click on the bud from the resources of the program, the picture png12.png should be copied into this folder, there is such a code which I found isn’t robs, tell me what the problem is? I found various articles, but nothing works

private void button1_Click(object sender, EventArgs e) { string dir = textBox1.Text; string FilePath = Application.StartupPath + "\\png12.png"; if (!File.Exists(FilePath)) { File.Copy(dir, FilePath, true); } } 

Marked as a duplicate by MSDN.WhiteKnight , 0xdb , PashaPash members c # Aug 20 '18 at 8:54 pm

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

1 answer 1

Here is my solution using threads, but you can use using sugar for Idisposable:

  private void button1_Click(object sender, EventArgs e) { string dir = textBox1.Text; string filePath = Application.StartupPath+ "\\Слайд1.png"; MemoryStream ms = new MemoryStream(); if (File.Exists(filePath)) { Image.FromFile(filePath).Save(ms, ImageFormat.Png); FileStream file = new FileStream(dir + "file.png", FileMode.Create, FileAccess.Write); ms.WriteTo(file); file.Close(); ms.Close(); } else { ms.Close(); } }