AntonioHernandez
New member
Hello all, I am fairly new to writing VB.NET and would really appreciate some help with a project I am working on. I am trying to develop a program that will copy a zip file from a local machine to a share on a remote machine. I am using the "OpenFileDialog" to select the file. The problem I am running into is the OpenFileDialog.FileName contains the entire path of the file. I only need the file name when using System.IO.File.Copy() and need to figure out a way to remove the path of the selected file. Here is my code...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strFileName As String
Dim strDestLocation As String
OpenFileDialog1.InitialDirectory = "C:\ZIP-Files\"
OpenFileDialog1.Title = "Please Select a ZIP File"
OpenFileDialog1.Filter = "ZIP Files|*.zip"
OpenFileDialog1.ShowDialog()
strFileName = OpenFileDialog1.FileName
strDestLocation = "\\ServerName\ShareName\" & (strFileName)
System.IO.File.Copy(strFileName, strDestLocation)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strFileName As String
Dim strDestLocation As String
OpenFileDialog1.InitialDirectory = "C:\ZIP-Files\"
OpenFileDialog1.Title = "Please Select a ZIP File"
OpenFileDialog1.Filter = "ZIP Files|*.zip"
OpenFileDialog1.ShowDialog()
strFileName = OpenFileDialog1.FileName
strDestLocation = "\\ServerName\ShareName\" & (strFileName)
System.IO.File.Copy(strFileName, strDestLocation)
End Sub