How to Copy , Delete File


VB.Net-Informations.com
SiteMap

The File Class is using the operations such as copying, moving, renaming, creating, opening, deleting, and appending to files.

  File.Copy("c:\\temp.txt", "c:\\copytemp.txt", True)

File.Delete("c:\\copytemp.txt")

IOException is the base class for exceptions thrown while accessing information using streams, files and directories. FileNotFoundException Class is thrown the exception when an attempt to access a file that does not exist on disk fails.

  Try
  	'code here
  Catch ex As System.IO.FileNotFoundException
  	'exception here

End Try

The following vb.net program shows how to use File Class for copying and deleting a text file and also its shows how to handle System.IO.FileNotFoundException Class.


Imports System.IO
Public Class Form1

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Try
			File.Copy("c:\\temp.txt", "c:\\copytemp.txt", True)
			File.Delete("c:\\copytemp.txt")
		Catch ex As System.IO.FileNotFoundException
			MsgBox(ex.ToString())
		End Try
	End Sub

End Class








More Source Code :
|  Home  |   VB.NET  |   C#  |   ASP.NET  |   SiteMap  |   Terms of Use  |   About  |