Mega Code Archive

 
Categories / ASP.Net Tutorial / File Directory
 

Delete a file (VB)

<%@ Import Namespace="System" %> <%@ Import Namespace="System.IO" %> <%@ Page Language="VB" %> <script runat="server">     Public Sub Page_Load(Source As Object, E As EventArgs)         MessageLiteral.Text = ""     End Sub          Public Sub DeleteFile(Source As Object, E As EventArgs)        'Delete the file if it exists      Try           If File.Exists(FileNameTextBox.Text) Then               File.Delete(FileNameTextBox.Text)                MessageLiteral.Text = "File has been deleted."           Else               MessageLiteral.Text = FileNameTextBox.Text & " does not exist."           End If     Catch _Error As Exception       MessageLiteral.Text = _Error.Message     End Try          End Sub </script> <html>   <head>     <title>Deleting a File</title>   </head>   <body>     <form runat="server">       <h4>Type Path/Name of file to delete it (disabled for live demo)       </h4>                <asp:TextBox id="FileNameTextBox" runat="server"/>         &nbsp;<asp:Button id="DeleteFileButton" onclick="DeleteFile" runat="server" Text="Delete File"></asp:Button>                <asp:Literal id="MessageLiteral" runat="server"></asp:Literal>            </form>   </body> </html>