How To Move A Folder To Another Folder In ASP.NET

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
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  3. <html xmlns="http://www.w3.org/1999/xhtml">  
  4. <head id="Head1" runat="server">  
  5. <title></title>  
  6. </head>  
  7. <body>  
  8. <form id="form1" runat="server">  
  9. <div>  
  10. <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />  
  11. </div>  
  12. </form>  
  13. </body>  
  14. </html>  
.CS Page
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7. using System.IO;  
  8. public partial class _Default : System.Web.UI.Page  
  9. {  
  10. protected void Page_Load(object sender, EventArgs e)  
  11. {  
  12. }  
  13. protected void Button1_Click(object sender, EventArgs e)  
  14. {  
  15. if (Directory.Exists(@"C:\abc"))  
  16. {  
  17. Directory.Move(@"C:\abc", @"C:\abcd");  
  18. }  
  19. }  
  20. }  
Detailed tutorials: