Nasıl Yapılır

C# İle Örnekler #69

c

C# Seçilen Resim Dosyanın Benzersiz İsim Verilerek Kopyalanması

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace resim_copy_guid
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        string dosyaYolu;
        string dosyaAdi;
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dosya = new OpenFileDialog();
            dosya.Filter = "Resim Dosyası |*.jpg;*.nef;*.png |  Tüm Dosyalar |*.*";
            dosya.ShowDialog();
            dosyaYolu = dosya.FileName;
            pictureBox1.ImageLocation = dosyaYolu;
 
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            dosyaAdi = Path.GetFileName(dosyaYolu); //Dosya adını alma
            string kaynak = dosyaYolu;
            string hedef = Application.StartupPath + @"\img\";
            string yeniad = Guid.NewGuid() + ".jpg"; //Benzersiz isim verme
            File.Copy(kaynak, hedef + yeniad);
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
 
        }
    }
}

 

Yazar Hakkında

Hız Hosting

Yorum Yap