CopyFile in VB.net
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: CopyFile in VB.net

  1. #1
    Join Date
    Jan 2012
    Posts
    3

    CopyFile in VB.net

    Hi
    Can anyone help me i am try ing to copy a file from one location to another useing an openfile dialog but it dosn't seem to work any ideas welcome. The code i am using is below

    FileCopy(OpenFileDialog1.FileName, "C:\temp\trial.tar")

  2. #2
    Join Date
    May 2002
    Location
    Boston
    Posts
    66

    Re: CopyFile in VB.net

    Hi,

    try using the File Class

    Code:
    Imports System.IO.File
    
    
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Try
    
            
                Dim FileToCopy As String
                Dim NewCopy As String
    
                OpenFileDialog1.ShowDialog()
    
                FileToCopy = OpenFileDialog1.FileName.ToString
    
                'FileToCopy = "c:\temp\test1.txt"
                NewCopy = "c:\temp\test2.txt"
    
                If System.IO.File.Exists(FileToCopy) = True Then
                    System.IO.File.Copy(FileToCopy, NewCopy, True)
                    MessageBox.Show("File Copied")
                Else
                    MessageBox.Show("File doesn't exist")
                End If
    
            Catch ex As Exception
                MessageBox.Show(ex.Message)
    
            End Try
        End Sub
    End Class
    Curt

  3. #3
    Join Date
    Jan 2012
    Posts
    3

    Re: CopyFile in VB.net

    Thanks
    I'll give that a go over the weekend and let you know

  4. #4
    Join Date
    Jan 2012
    Posts
    3

    Smile Re: CopyFile in VB.net

    Ok that seems to work ok
    However if i try to copy a file from my external usb drive it comes up with an error of file already in use

    Any idea's!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center