Hello, in the code I'm developing I need to get a file name. I used an OpenFileDialog for the user to select a file, and after selecting, the system returns the directory of this file within a string. Example: "C: \ Users \ Lucas \ Documents \ Image.png".
But I need to copy this file to the project folder (Application.StartupPath) however, for this I need to get the name of this file from the slash ("\ Image.png"), but I do not know how to do it, I tried it in different ways and I could not.
Below is the OpenFileDialog Code (it works):
Private Sub btnProcurar_Click(sender As Object, e As EventArgs) Handles btnProcurar.Click
Dim OFD As New OpenFileDialog()
OFD.Filter = "Imagens (*.PNG; *.JPG)|*.PNG;*.JPG|" & "All files (*.*)|*.*"
OFD.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal)
OFD.FilterIndex = 1
OFD.Multiselect = False
OFD.Title = "Selecionar Comprovante de Depósito"
If (OFD.ShowDialog() = DialogResult.OK) Then
NomeArquivo = OFD.FileName
txtCaminhoComprovante.Text = NomeArquivo
End If
End Sub
Below is the code I mentioned above (which I can not do):
Private Sub btnConfirmar_Click(sender As Object, e As EventArgs) Handles btnConfirmar.Click
If txtValor.TextLength < 4 Then
MessageBox.Show("O valor informado no campo deve ter no mínimo quatro caracteres! Exemplo: 0.00", "FinanSys - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
If txtCaminhoComprovante.TextLength < 1 Then
MessageBox.Show("Você deve selecionar um comprovante do depósito informado!", "FinanSys - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
If File.Exists(NomeArquivo) Then
Dim StringReversa As String = StrReverse(NomeArquivo)
Dim Barra As String = Asc(92)
Dim CaracterObtido As String = ""
For i As Integer = 0 To StringReversa.Length - 1
If String.Compare(CaracterObtido = StringReversa.Substring(i, 1), Barra) Then
CaracterObtido = StringReversa.Substring(i, 1)
Exit For
End If
Next
//FileCopy(NomeArquivo, Application.StartupPath)
MsgBox(CaracterObtido)
Else
MessageBox.Show("O comprovante selecionado não existe!", "FinanSys - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End If
End If
End Sub
In short, what I need is to get the file name "\ Image.png" from the string "C: \ Users \ Lucas \ Documents \ Image.png"