Copying or Moving a File (VB) : FileInfo « File Directory « ASP.Net






Copying or Moving a File (VB)


<%@ Page Language="VB" %>
<script runat="server">
Sub CopyFile_Click(sender As Object, e As System.EventArgs)
  Try
    Dim sourceFile As String = Server.MapPath("Data.txt")
    Dim destinationFile As String = Server.MapPath("Datacopy.txt")
    System.IO.File.Copy(sourceFile, destinationFile)
  Catch Ex As Exception
    MessageLabel.Text = Ex.Message
  End Try
End Sub

Sub MoveFile_Click(sender As Object, e As System.EventArgs)
  Try
    Dim sourceFile As String = Server.MapPath("Data.txt")
    Dim destinationFile As String = Server.MapPath("Datamove.txt")
    System.IO.File.Move(sourceFile, destinationFile)
  Catch Ex As Exception
    MessageLabel.Text = Ex.Message
  End Try
End Sub
</script>
<html>
  <head>
    <title>Copying or Moving a File</title>
  </head>
  <body>
    <form id="MainForm" runat="server">
      Copy "Data.txt" to "Datacopy.txt"
      <asp:button id="CopyFile" runat="server" text="Copy File" onclick="CopyFile_Click" />
      <br />
      Move "Data.txt" to "Datamove.txt"
      <asp:button id="MoveFile" runat="server" text="Move File" onclick="MoveFile_Click" />
      <br />
      <asp:Label ID="MessageLabel" Runat="server" />
    </form>
  </body>
</html>

 








Related examples in the same category

1.Inquiring Information About a File (C#)
2.Inquiring Information About a File (VB)
3.Copying or Moving a File (C#)