--> The following code is for delete file using C# code.
--> If you want to delete file using Asp.net then use following code on your code behind file
--> If you want to delete file using Asp.net then use following code on your code behind file
Other Articles - Step by step solution
------------------------------------------------------------------------
three tier architecture in asp.net
how to connect MS access in asp.net
how to access website in LAN
------------------------------------------------------------------------
Your .aspx file should be like this
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblStatus" runat="server" />
<br />
<asp:Button Text="Delete File" ID="btnDeleteFile" runat="server" OnClick="btnDeleteFile_Click" />
</div>
</form>
</body>
</html>
And your code behind file should be like this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnDeleteFile_Click(object sender, EventArgs e)
{
string FileName = "here-my-file-name";
string YourPath = Server.MapPath("FolderName") + "\\" + FileName;
FileInfo GetMyFile = new FileInfo(YourPath);
if (GetMyFile.Exists)
{
GetMyFile.Delete();
lblStatus.Text = "File is Deleted";
}
else
{
lblStatus.Text = "File is not Delete";
}
}
}
three tier architecture in asp.net
how to connect MS access in asp.net
how to access website in LAN
------------------------------------------------------------------------
Your .aspx file should be like this
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblStatus" runat="server" />
<br />
<asp:Button Text="Delete File" ID="btnDeleteFile" runat="server" OnClick="btnDeleteFile_Click" />
</div>
</form>
</body>
</html>
And your code behind file should be like this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnDeleteFile_Click(object sender, EventArgs e)
{
string FileName = "here-my-file-name";
string YourPath = Server.MapPath("FolderName") + "\\" + FileName;
FileInfo GetMyFile = new FileInfo(YourPath);
if (GetMyFile.Exists)
{
GetMyFile.Delete();
lblStatus.Text = "File is Deleted";
}
else
{
lblStatus.Text = "File is not Delete";
}
}
}
No comments:
Post a Comment