How to delete file from folder in ?

Posted by Ranjeet_8 under VB.NET category on | Points: 40 | Views : 1287
when the user click on button then if the file exists then it will be deleted.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Delete" onclick="Button1_Click" />

// VB Code

Imports System.IO
Protected Sub Button1_Click(sender As Object, e As EventArgs)
Dim TheFile As New FileInfo((MapPath(".") & "\Your Folder Location\") + TextBox1.Text & ".Doc")
If TheFile.Exists Then
File.Delete((MapPath(".") & "\Your Folder Location\") + TextBox1.Text & ".Doc")
End If
End Sub

Comments or Responses

Login to post response