منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : كود نسخ ملف تم اختياره في الكومبوبكس
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
هناك ملفات في فولدر تعبا في الكمبوبكس
اريد كود يقوم بنسخ ملف تم اختياره من الكمبوبكس
اي لما اختار ملف من الكمبوبكس واظغط زر يقوم بنسخ الملف الى المسار المحدد
وشكرا
السلام عليكم

تفضل الكود
كود :
Dim sourceFileName As String = ComboBox1.Text
Dim distFileName As String = "E:\folder\" & IO.Path.GetFileName(ComboBox1.Text)

IO.File.Copy(sourceFileName, distFileName, True)
(13-02-17, 07:51 PM)مساعدة كتب : [ -> ]السلام عليكم

تفضل الكود
كود :
Dim sourceFileName As String = ComboBox1.Text
Dim distFileName As String = "E:\folder\" & IO.Path.GetFileName(ComboBox1.Text)

IO.File.Copy(sourceFileName, distFileName, True)

لم ينفع طلع ارور
جرب الكود التالي

اولاً تحميل الملفات من مجلد معين الى الكمبوبوكس ويوضع في الحدث  Form1_Load او بداخل زر معين
PHP كود :
Try
 
           'تحميل الملفات
            Dim dir = Application.StartupPath & "\New folder"
            For Each file As String In System.IO.Directory.GetFiles(dir)
                ComboBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(file))
            Next
            '
تحديد اخر قيمة تم اختيارها قبل اغلاق الفورم
            ComboBox1
.SelectedIndex My.Settings.file_name

        Catch ex 
As Exception
        End 
Try 
ثانياً حفظ قيمة الملف الذي تم اختياره
PHP كود :
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.ObjectByVal e As System.EventArgsHandles ComboBox1.SelectedIndexChanged
        
        If ComboBox1
.SelectedIndex <> -1 Then
            
'حفظ قيمة الملف الذي تم اختياره من الكمبوبوكس
            My.Settings.file_name = ComboBox1.SelectedIndex
            My.Settings.Save()
        End If
    End Sub 
ثالثاً تحديد مكان حفظ الملف
PHP كود :
Private Sub Button1_Click(sender As ObjectAs EventArgsHandles Button1.Click
        Dim fd 
As New FolderBrowserDialog
        If fd
.ShowDialog Windows.Forms.DialogResult.OK Then
            TextBox1
.Text fd.SelectedPath
        End 
If
 
   End Sub 

رابعاً نسخ الملف 
PHP كود :
Private Sub Button2_Click(sender As ObjectAs EventArgsHandles Button2.Click
        If TextBox1
.Text Nothing Then
            MsgBox
("حدد مسار حفظ الملف")
 
           Button1.Focus()
 
           Exit Sub
        End 
If

 
       Dim path_ As String Application.StartupPath "\New folder\" & ComboBox1.Text & ".txt"
        IO.File.Copy(path_, TextBox1.Text & "
\" & ComboBox1.Text & ".txt", True)
    End Sub 
(14-02-17, 02:45 PM)Adrees كتب : [ -> ]جرب الكود التالي

اولاً تحميل الملفات من مجلد معين الى الكمبوبوكس ويوضع في الحدث  Form1_Load او بداخل زر معين
PHP كود :
Try
 
           'تحميل الملفات
            Dim dir = Application.StartupPath & "\New folder"
            For Each file As String In System.IO.Directory.GetFiles(dir)
                ComboBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(file))
            Next
            '
تحديد اخر قيمة تم اختيارها قبل اغلاق الفورم
            ComboBox1
.SelectedIndex My.Settings.file_name

        Catch ex 
As Exception
        End 
Try 
ثانياً حفظ قيمة الملف الذي تم اختياره
PHP كود :
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.ObjectByVal e As System.EventArgsHandles ComboBox1.SelectedIndexChanged
        
        If ComboBox1
.SelectedIndex <> -1 Then
            
'حفظ قيمة الملف الذي تم اختياره من الكمبوبوكس
            My.Settings.file_name = ComboBox1.SelectedIndex
            My.Settings.Save()
        End If
    End Sub 
ثالثاً تحديد مكان حفظ الملف
PHP كود :
Private Sub Button1_Click(sender As ObjectAs EventArgsHandles Button1.Click
        Dim fd 
As New FolderBrowserDialog
        If fd
.ShowDialog Windows.Forms.DialogResult.OK Then
            TextBox1
.Text fd.SelectedPath
        End 
If
 
   End Sub 

رابعاً نسخ الملف 
PHP كود :
Private Sub Button2_Click(sender As ObjectAs EventArgsHandles Button2.Click
        If TextBox1
.Text Nothing Then
            MsgBox
("حدد مسار حفظ الملف")
 
           Button1.Focus()
 
           Exit Sub
        End 
If

 
       Dim path_ As String Application.StartupPath "\New folder\" & ComboBox1.Text & ".txt"
        IO.File.Copy(path_, TextBox1.Text & "
\" & ComboBox1.Text & ".txt", True)
    End Sub 
شكرا لك اخي الله يحفظك
لقد استفدة الكثير الكثير من هذا الكود الله يجازيك الف خير