Copy File From One Location To Another + Urgent + Sourabh Das
-
Hi All, After A long time.. Hope u all are good.. I am having btnUpload and btnTransfer. On btnUpload I open a openFileDialogue select any type of file and at transfer i want to transfer it to another location suppose D:\TransferTest\. But its giving this error Could not find a part of the path 'D:\TransferTest\'. The code is as below :
Dim filename As String
Dim ofd As OpenFileDialogPrivate Sub btnUpload\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click ofd = New OpenFileDialog() ofd.Filter = "All Files|\*.\*" ofd.ShowDialog() If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then filename = ofd.FileName() txtFile.Text = filename End If End Sub Private Sub btnTransfer\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTransfer.Click File.Copy(filename, "D:\\TransferTest\\") End Sub
Help with a code tip... its a urgent.. Regards, Sourabh
Thanks and Regards,
-
Hi All, After A long time.. Hope u all are good.. I am having btnUpload and btnTransfer. On btnUpload I open a openFileDialogue select any type of file and at transfer i want to transfer it to another location suppose D:\TransferTest\. But its giving this error Could not find a part of the path 'D:\TransferTest\'. The code is as below :
Dim filename As String
Dim ofd As OpenFileDialogPrivate Sub btnUpload\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click ofd = New OpenFileDialog() ofd.Filter = "All Files|\*.\*" ofd.ShowDialog() If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then filename = ofd.FileName() txtFile.Text = filename End If End Sub Private Sub btnTransfer\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTransfer.Click File.Copy(filename, "D:\\TransferTest\\") End Sub
Help with a code tip... its a urgent.. Regards, Sourabh
Thanks and Regards,
-
Hi All, After A long time.. Hope u all are good.. I am having btnUpload and btnTransfer. On btnUpload I open a openFileDialogue select any type of file and at transfer i want to transfer it to another location suppose D:\TransferTest\. But its giving this error Could not find a part of the path 'D:\TransferTest\'. The code is as below :
Dim filename As String
Dim ofd As OpenFileDialogPrivate Sub btnUpload\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click ofd = New OpenFileDialog() ofd.Filter = "All Files|\*.\*" ofd.ShowDialog() If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then filename = ofd.FileName() txtFile.Text = filename End If End Sub Private Sub btnTransfer\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTransfer.Click File.Copy(filename, "D:\\TransferTest\\") End Sub
Help with a code tip... its a urgent.. Regards, Sourabh
Thanks and Regards,
Hi, in Windows you can only create/move/copy files to existing folders, so if either D:\ or D:\TransferTest\ does not exist, you would get such error. You should use Directory.CreateDirectory() to create a folder (no need to test for existence first!). :)
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
-
Hi All, After A long time.. Hope u all are good.. I am having btnUpload and btnTransfer. On btnUpload I open a openFileDialogue select any type of file and at transfer i want to transfer it to another location suppose D:\TransferTest\. But its giving this error Could not find a part of the path 'D:\TransferTest\'. The code is as below :
Dim filename As String
Dim ofd As OpenFileDialogPrivate Sub btnUpload\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click ofd = New OpenFileDialog() ofd.Filter = "All Files|\*.\*" ofd.ShowDialog() If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then filename = ofd.FileName() txtFile.Text = filename End If End Sub Private Sub btnTransfer\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTransfer.Click File.Copy(filename, "D:\\TransferTest\\") End Sub
Help with a code tip... its a urgent.. Regards, Sourabh
Thanks and Regards,
Private Sub btnTransfer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTransfer.Click if not io.directory.exists("D:\TransferTest\") then io.directory.createdirectory("D:\Tran.....") enf if File.Copy(filename, "D:\TransferTest\") End Sub
-
Private Sub btnTransfer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTransfer.Click if not io.directory.exists("D:\TransferTest\") then io.directory.createdirectory("D:\Tran.....") enf if File.Copy(filename, "D:\TransferTest\") End Sub
so far for "no need to test for existence"... :)
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets