Peter Kiers
asked on
Copy a file to the application directory
Hi,
I have this:
if (System.IO.Directory.GetFi les(@"\REP ORT\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
I have this:
if (System.IO.Directory.GetFi
{
// file exists
}
And if a file exists how can I copy that file to the application's folder?
Greetings,
Peter Kiers
http://msdn.microsoft.com/en-us/library/9706cfs5.aspx
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks James, this is the right solution.
Greetings,
Peter Kiers
Greetings,
Peter Kiers