ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Copy all folder and files from one directory to another in C# and VB.Net<p>Hi <a class="username" rel="PRA"> PRA</a>,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">C#</span></strong></p> <pre class="brush: csharp">protected void btnCopy_Click(object sender, EventArgs e) { &nbsp;&nbsp;&nbsp; var remote = @&#34;\\192.168.1.1\&#34;; &nbsp;&nbsp;&nbsp; var local = @&#34;D:\&#34;; &nbsp;&nbsp;&nbsp; // Create all the directories. &nbsp;&nbsp;&nbsp; foreach (string dirPath in Directory.GetDirectories(remote, &#34;*&#34;, SearchOption.AllDirectories)) &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Directory.CreateDirectory(dirPath.Replace(remote, local)); &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; // Copy all the files &amp; Replaces any files with the same name. &nbsp;&nbsp;&nbsp; foreach (string newPath in Directory.GetFiles(remote, &#34;*.*&#34;, SearchOption.AllDirectories)) &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File.Copy(newPath, newPath.Replace(remote, local), true); &nbsp;&nbsp;&nbsp; } }</pre> <p><strong><span style="text-decoration: underline;">VB.Net</span></strong></p> <pre class="brush: vb">Protected Sub btnCopy_Click(ByVal sender As Object, ByVal e As EventArgs) Dim remote = &#34;\\192.168.1.1\&#34; Dim local = &#34;D:\&#34; &#39; Create all the directories. For Each dirPath As String In Directory.GetDirectories(remote, &#34;*&#34;, SearchOption.AllDirectories) Directory.CreateDirectory(dirPath.Replace(remote, local)) Next &#39; Copy all the files &amp; Replaces any files with the same name. For Each newPath As String In Directory.GetFiles(remote, &#34;*.*&#34;, SearchOption.AllDirectories) File.Copy(newPath, newPath.Replace(remote, local), True) Next End Sub</pre>https://www.aspforums.net:443/Threads/142738/Copy-all-folder-and-files-from-one-directory-to-another-in-C-and-VBNet/https://www.aspforums.net:443/Threads/142738/Copy-all-folder-and-files-from-one-directory-to-another-in-C-and-VBNet/Tue, 16 Oct 2018 01:42:16 GMT