Copy a file to the application directory

Hi,

I have this:

if (System.IO.Directory.GetFiles(@"\REPORT\XML", "G*.xml").Length > 0)
{
    // file exists
}

And if a file exists how can I copy that file to the application's folder?

Greetings,


Peter Kiers
LVL 1
peterkiersAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vel EousResearch & Development ManagerCommented:
0
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
Hello,

Imports System
Imports System.IO

Public Class Test
    Public Shared Sub Main()
        ' Specify the directories you want to manipulate.
        Dim path As String = "c:\temp\MyTest.txt"
        Dim path2 As String = path + "temp"

        Try
            Dim fs As FileStream = File.Create(path)
            fs.Close()
            ' Ensure that the target does not exist.
            File.Delete(path2)

            ' Copy the file.
            File.Copy(path, path2)
            Console.WriteLine("{0} copied to {1}", path, path2)

            ' Try to copy the same file again, which should fail.
            File.Copy(path, path2)
            Console.WriteLine("The second Copy operation succeeded, which was not expected.")

        Catch e As Exception
            Console.WriteLine("The second Copy operation failed, as expected.")
        End Try
    End Sub
End Class
0
Jacques Bourgeois (James Burger)PresidentCommented:
System.IO.File.Copy ( "YourFileWithPath", System.IO.Path.Combine ( Application.ExecutablePath, "YourFileName" ) );
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
peterkiersAuthor Commented:
Thanks James, this is the right solution.

Greetings,

Peter Kiers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.