C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How To Move A Folder To Another Folder In ASP.NET
WhatsApp
Pankaj Pandey
5y
11.9
k
0
2
25
Blog
We can use the Directory class and its Move method to move a folder. Here is a simple ASP.NET Web page that shows how to move a folder with its content. See links below for detailed code samples.
.aspx page
<%@ Page Language=
"C#"
AutoEventWireup=
"true"
CodeFile=
"Default.aspx.cs"
Inherits=
"_Default"
%>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<html xmlns=
"http://www.w3.org/1999/xhtml"
>
<head id=
"Head1"
runat=
"server"
>
<title></title>
</head>
<body>
<form id=
"form1"
runat=
"server"
>
<div>
<asp:Button ID=
"Button1"
runat=
"server"
Text=
"Button"
OnClick=
"Button1_Click"
/>
</div>
</form>
</body>
</html>
.CS Page
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
Button1_Click(
object
sender, EventArgs e)
{
if
(Directory.Exists(@
"C:\abc"
))
{
Directory.Move(@
"C:\abc"
, @
"C:\abcd"
);
}
}
}
Detailed tutorials:
Working With FileInfo Class In C#
Working With File Class In C#
Working With Directories and Folders In C#
How to move a folder to another folder with whole data in ASP.Net in same drive
People also reading
Membership not found