Hello There, Guest! RegisterLogin with Facebook
Login with Facebook

>>> Anna University Sixth Semester Question Bank Collection (R2013) ECE,MECH,CSE,IT,EEE,CIVIL,EIE
>>> Anna University Study Materials for all Departments
>>> Anna University Question Papers : April May June 2015 Question Papers | Nov Dec 2014 and Jan 2015 Question Papers

Register or Login to Submit Study Materials , Shoutbox and also to access Many Features !!

Vidyarthiplus Shop :: Handwritten Premium Lecture Notes
Share your Study Materials with us
Share your Study Materials with us : Click Here

Delete a File from Asp.net Uploaded Folder using C#, VB.NET


Here I will explain how to delete a file from a folder in

To implement this functionality we need to write the following code like as shown below

string FileName ="test.txt";
string Path = "E:\\" + FileName;
FileInfo file = new FileInfo(Path);
if (file.Exists)

If you want to see it in complete example check below code

Enter File Name to Delete:

Now open code behind file and add following namespaces

C# Code

using System;
using System.Drawing;
using System.IO;

After that write the following code in code behind

protected void btnDelete_Click(object sender, EventArgs e)
string filename =txtName.Text;
string path = "E:\\" + filename;
FileInfo file = new FileInfo(path);
if (file.Exists)
lblResult.Text = filename + " file deleted successfully";
lblResult.ForeColor = Color.Green;
lblResult.Text = filename + " file not exists in filepath";
lblResult.ForeColor = Color.Red;


Imports System.Drawing
Imports System.IO
Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

End Sub
Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim filename As String = txtName.Text
Dim path As String = "E:\" & filename
Dim file As New FileInfo(path)
If file.Exists Then
lblResult.Text = filename & " file deleted successfully"
lblResult.ForeColor = Color.Green
lblResult.Text = filename & " file not exists in filepath"
lblResult.ForeColor = Color.Red
End If
End Sub
End Class
Here it is Demo Idea
[Image: KSbE5.gif]

#Praise the creator not the creations#


We can do it by VB with out any cons

[Image: An9XX.gif]



Recommend on Google

Vidyarthiplus Whatsapp