9/28/2011

VB.Net : Copy file to new path.

First step Import System.IO.File on top code.

and use code in button.
  1.  
  2. Dim FileToCopy As String
  3. Dim NewCopy As String
  4.  
  5. FileToCopy = "C:\Users\Owner\Documents\test.txt"  'Old path
  6. NewCopy = "C:\Users\Owner\Documents\NewTest.txt"  'New path
  7.  
  8. If System.IO.File.Exists(FileToCopy) = True Then
  9. System.IO.File.Copy(FileToCopy, NewCopy) ' copy วางทับชื่อซ้ำไม่ได้
  10. 'System.IO.File.Copy(FileToCopy, NewCopy, True) 'copy วางและแทนที่
  11. MsgBox("File Copied")
  12. End If


example :

  1.    Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  2.         Dim FileToCopy As String
  3.         Dim NewCopy As String
  4.         Dim NameImage As String
  5.  
  6.         FileToCopy = TextBox_URL.Text 'name of text save url.
  7.         NewCopy = "\\server3\7C งทส\00-อื่น ๆ\Personal Data\สุวิทย์  จำปาหอม\ImageAMS\1.jpg"
  8.  
  9.         If System.IO.File.Exists(FileToCopy) = True Then
  10.             System.IO.File.Copy(FileToCopy, NewCopy)
  11.             MsgBox("File Copied")
  12.         End If
  13.     End Sub

No comments:

Post a Comment