Learn How to use the Copy Web Site Tool in ASP.NET 3.5 C#
In this tutorial we will show you how to use the Copy Web Site Tool in ASP.NET 3.5 to copy files between your current Web site and another Web site.
In this tutorial we will demonstrate how to copy files between web sites and how to synchronize two Web sites so that they have the same version of each file. You will work with both a shared and local web site and local Web site as you would during production. A classic scenario might be that the shared Web site is on another server, whether it is a staging or production server.
When working on a Web site, you create a local version of the site and then copy the files from the shared server to your computer. After finishing all of your updates, you just simply copy the files back to the shared server. Another great advantage of this tutorial is that you can see what it might be like to work in an environment with more than one developer.
For example, when there is more than one developer working on a single Web site, they will copy files, edit them locally, and then copy them back to the shared server. This scenario will demonstrate just that by having you create two different Web sites on your local computer and work with the Copy Web Site tool as you would in a production environment, minus the second computer.
To start we will create a Web site. Open Visual developer and File > New Web site > ASP.NET Web site. Please name the Web site CopyWebSiteTool.aspx and click > Ok.
In the Solution Explorer, Right-click the name of the Web site and click > Add New Item > Web Form, name it Cars.aspx and click > Add. Once the new page appears in the editor switch to Design View and type Cars. Then select what you just typed and then on the Formatting toolbar, click > Heading 1. Underneath the heading “Cars” press enter and type “This page list the cars that we offer our customers”. Do the same thing to another page called “Trucks”.
Then open the default.aspx page and type “This is the Home Page” and underneath that heading type “welcome!”
To add links onto the default.aspx page simply switch to Design View and drag over a Hyperlink control onto the page and set the text to “Trucks” and NavigateUrl to: /Trucks.aspx. Then do the same for “Cars”. Save and Run. It should resemble this example:
Test to make sure that both links work correspond to the correct pages.
Now we want to create the source Web site that we can use to copy files to and from. Knowing that both Web sites reside on your local computer as described earlier, the first Web site will function as the shared Web site. Now we will create the Web site that you will use to edit files. To start, click > Close Project.
Then create a new Web site and name it LocalCopyWebSiteTool. So you should have a shared Web site on your computer named CopyWebSiteTool and a new one open called LocalCopyWebSiteTool. At this point if you were a new developer you would want to copy all the files from the shared Web site to your local Web site.
To copy all the files from the shared Web site to the local Web site on the Website menu, click > Copy Web Site. Your page should look like this:
Then at the top of the Design View section of where the Web site is click > Connect. The open Web site dialog box appears and choose the CopyWebSiteTool.aspx and click > Open. (This is where you would type in the URL of the server if the Web site was on another computer).
All the files from the shared site are listed under Remote Web Site. Some files have symbols listed next to them describing their status. The arrows suggest the direction of which way you want to copy files.
The (?) next to a file suggest that the same name of a file exists in both sites. Keeping in mind that if we were to synchronize the Web sites, these files would not automatically copied. Rather for each file you are prompted to do one of three things. Copy file from source to remote, remote to source, or to not synchronize it at all.
Now under the Remote Web site select all files and folders.
And click > Left-arrow button (the arrow is not labeled unless you mouse over it) to copy all files from the shared to local site. This is a great instance for a new developer on an existing Web site obtaining the most current versions of the Web site files to edit or update them. After clicking the arrow to copy all files from the shared Web site to your local one you want to Confirm all Overwrites. Then click > Yes.
In this case it is safe to overwrite all local versions of any file being copied. Be careful and read through all steps carefully.