Advertisement
ferdhika31

Image

Apr 19th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.90 KB | None | 0 0
  1. 'import library
  2. Imports System.IO.File
  3.  
  4. 'Variable
  5. Dim FileExtension() As String
  6.     Dim FileAdress As String = Application.StartupPath & "\galeri\default.png"
  7.     Dim FileName() As String
  8.     Dim Destination As String = System.Environment.CurrentDirectory & "\galeri\"
  9.     Dim tmpFileName As String
  10.  
  11. 'Button
  12. Private Sub btnUnggah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUnggah.Click
  13.     'ofd name komponen open file dialog
  14.         ofd.InitialDirectory = "\"
  15.         ofd.FileName = "NamaFIle"
  16.         ofd.Filter = "Ekstensi Gambar (JPEG,GIF,BMP,PNG,ICO)|*.jpg;*.jpeg;*.gif;*.bmp;*.png;*ico"
  17.         ofd.ShowDialog()
  18.     End Sub
  19.  
  20. 'Open File Dialog
  21. Private Sub ofd_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ofd.FileOk
  22.         tmpFileName = ofd.SafeFileName
  23.         FileAdress = ofd.FileName
  24.         FileExtension = tmpFileName.Split(".")
  25.         pb.Load(ofd.FileName)
  26.     End Sub
  27.  
  28.  
  29. 'Pas disimpen
  30. If System.IO.Directory.Exists(Destination) Then 'jika direktori maka memilih ini
  31.                     If System.IO.File.Exists(Destination & txtUname.Text.Replace("'", "'") & ".jpg") Then
  32.                         MsgBox("File Foto Sudah Ada", MsgBoxStyle.Information)
  33.                     Else
  34.                         System.IO.File.Copy(FileAdress, Destination & txtUname.Text.Replace("'", "'") & ".jpg")
  35.                     End If
  36.                 Else
  37.                     System.IO.Directory.CreateDirectory(Destination) 'membuat direktori jika tidak ada
  38.                     If System.IO.File.Exists(Destination & txtUname.Text.Replace("'", "'") & ".jpg") Then
  39.                         MsgBox("File Foto Sudah Ada", MsgBoxStyle.Information)
  40.                     Else
  41.                         System.IO.File.Copy(FileAdress, Destination & txtUname.Text.Replace("'", "'") & ".jpg")
  42.                     End If
  43.                 End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement