Delete a file (VB) : File « File Directory « ASP.NET Tutorial

Home
ASP.NET Tutorial
1.ASP.Net Instroduction
2.Language Basics
3.ASP.net Controls
4.HTML Controls
5.Page Lifecycle
6.Response
7.Collections
8.Validation
9.Development
10.File Directory
11.Sessions
12.Cookie
13.Cache
14.Custom Controls
15.Profile
16.Configuration
17.LINQ
18.ADO.net Database
19.Data Binding
20.Ajax
21.Authentication Authorization
22.I18N
23.Mobile
24.WebPart
25.XML
ASP.NET Tutorial » File Directory » File 
10.1.5.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.TextThen
              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>
10.1.File
10.1.1.Get file information (VB.net)
10.1.2.Opening a File (C#)
10.1.3.Opening a File (VB)
10.1.4.Delete a file (C#)
10.1.5.Delete a file (VB)
10.1.6.Creating a File (C#)
10.1.7.Creating a File (VB)
10.1.8.Load file content to DropDownList (C#)
10.1.9.Load file content to DropDownList (VB)
10.1.10.Rename File
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.