Dela via


Walkthrough: Copying a Web Site Using the Copy Web Site Tool

This walkthrough shows you how to use the Copy Web Site tool to copy files between your current Web site and another Web site.

During this walkthrough, you will learn how to do the following:

  • Copy files between Web sites.

  • Synchronize two Web sites so that they have the same version of each file.

    Note

    If you copy an application that contains a reference to a custom component that is registered in the GAC, the component will not be copied with the application. For more information, see How to: Add a Reference to a .NET or COM Component in a Web Site.

Prerequisites

In order to complete this walkthrough, you will need the following:

  • Visual Web Developer

  • The .NET Framework

Creating the Shared Web Site

In this walkthrough you will work with both a shared and local Web site as you might in a production environment. A typical scenario is that the shared Web site is on another server, such as a staging server or production server. When you want to work on the site, you create a local version of the site, and then copy the files from the shared server to your computer. When you have finished your updates, you copy the local files back to the shared server.

This walkthrough will also let you see what it might be like to work in an environment where there is more than one developer. If there were other developers working on the site, they might also download files, edit them locally, and then copy the files back to the shared server. Therefore, not only must you copy files from the local Web site to the shared Web site, but you also might have to copy updated versions of files on the shared Web site to the local Web site.

This walkthrough emulates this scenario by having you create two Web sites. Instead of residing on separate computers, the Web sites both reside on the local computer. This lets you work with the Copy Web Site tool as you would in a production environment but without requiring you to use a second computer. All tasks that you perform in this walkthrough work identically when the shared Web site is on another computer. You will emulate the edits made by other developers by using Notepad to change files.

To create a file system Web site

  1. Open Visual Web Developer.

  2. On the File menu, click NewWeb Site.

    The New Web Site dialog box appears.

  3. Under Visual Studio installed templates, click ASP.NET Web Site.

  4. In the left-most Location list, click File System, and then in the right-most Location list, enter C:\SharedWebSite.

    Note

    Procedures later in the walkthrough assume that you are working with a Web site named SharedWebSite.

  5. In the Language list, click the programming language that you prefer to work in.

  6. Click OK.

    Visual Web Developer creates the folder and a new page named Default.aspx.

Creating Test Pages

For this walkthrough, you will create some simple pages with known names.

Note

To test copying Web pages, it is not important that you have specific pages. However, later in the walkthrough you will edit the pages that you create in the next procedure.

To create test pages

  1. In Solution Explorer, right-click the name of the Web site, and then click Add New Item.

  2. Under Visual Studio installed templates, click Web Form.

  3. In the Name box, type Services.aspx.

  4. In the Language list, click the programming language that you prefer to work in.

  5. Click Add.

    The new page appears in the editor.

  6. Switch to Design view.

  7. In the page, type Services, highlight to select the text that you just entered, and then on the Formatting toolbar, click Heading 1 <H1>.

  8. Position the pointer at the end of the text.

  9. Press ENTER to create a new paragraph, and then type This page lists the services that we offer.

  10. Save the page.

  11. Repeat Steps 1 through 9 to create a page named Products.aspx with a heading of Products and the text This page lists the products that we sell.

  12. Open the Default.aspx page and switch to Design view.

  13. In the page, type the heading Home and the text Welcome to our Web site.

Now you will add controls on the home page (Default.aspx) to link to the pages that you just created.

  1. Open the Default.aspx page and switch to Design view.

  2. From the Standard group in the Toolbox, drag a Hyperlink control onto the page.

  3. Set Text to Products and href to ~/Products.aspx.

  4. Drag another Hyperlink control onto the page, and then set Text to Services and href to ~/Services.aspx.

  5. Save your files.

Testing the Web Site

Now you will test that the Web site works as you expect.

To test the Web site

  1. In Solution Explorer, right-click Default.aspx, and then click View in Browser.

    The page appears in the browser.

  2. Click Products and Services to confirm that the links work.

  3. Close the browser.

Creating the Source Web Site

In this part of the walkthrough, you will create a second Web site that you can use to copy files to and from. As explained in "Creating the Shared Web Site," earlier in this walkthrough, both Web sites are on your computer, but the first Web site functions as the shared Web site. The Web site that you will create in this part of the walkthrough functions as the site that you would use to edit files.

To create the source Web site

  1. On the File menu, click Close Project to close SharedWebSite.

  2. On the File menu, click NewWeb Site.

  3. Under Visual Studio installed templates, click ASP.NET Web Site.

  4. In the left-most Location list, click File System, and then in the right-most Location list, enter C:\LocalWebSite.

  5. Click OK.

Copying Files from the Shared to the Local Web Site

At this point, a shared Web site exists on your computer and you have a new Web site open. If you were a new developer on a project, you would first want to obtain all files from the shared Web site and copy the files to your local Web site.

To copy all files from the shared Web site to the local Web site

  1. On the Website menu, click Copy Web Site.

    The Copy <Websitename> tool appears.

  2. Click Connect.

    The Open Web Site dialog box appears.

  3. Click File System.

  4. In the Folder box, type C:\SharedWebSite.

    If the shared site were on another computer, you would type the URL of the server.

  5. Click Open.

    The files from the shared site are listed under Remote Web Site.

    Many of the files have symbols next to them that indicate their status. The arrow symbol shows you the direction that a file will be copied if you synchronize the sites. Currently, the Services.aspx and Products.aspx files in the Remote Web Site list point to the Source Web Site list, because if you synchronize the Web sites, the Services.aspx and Products.aspx files will be copied from the shared site to the local site.

    The Default.aspx files have question marks (?) next to them. This indicates that the file has the same name in both sites, but different timestamp data and no information about the last time the files were copied. If you synchronize the Web sites, these files will not be automatically copied. Instead, for each file, a dialog box is displayed that provides three options: copy the file from source to remote, copy it from remote to source, or do not synchronize it.

  6. Under Remote Web site, highlight to select all files and folders.

    In this case, you want to obtain copies of all files from the shared site. You are emulating a scenario where you are a new developer on an existing Web site and you want to obtain the most current versions of the Web site files. Because you have created a new local site, you do not have to copy any files from the local site to the shared site.

  7. Click the left-arrow button to copy the selected files from the shared site to the local site.

    The left-arrow button is not labeled unless you move the pointer over it, in which case a ToolTip appears. The arrow is pointing to Source Web Site.

    Visual Web Developer starts copying files. When it gets to the Default.aspx file, it prompts you for confirmation to overwrite the local copy of the file with the file from the shared site.

  8. In the Confirm File Overwrite dialog box, select the Apply to all check box, and then click Yes.

    In this case, it is safe to overwrite all local versions of any files that have duplicated file names, because you want the file versions from the shared site. When the copy process is finished, the lists in Source Web Site and Remote Web Site are the same.

    Note

    The Copy Web Site tool does not merge files, it only overwrites files.

Copying Individual Pages

You can use the Copy Web Site tool to copy all files or individual files. In this part of the walkthrough, you will create a new Web page in the source Web site, and then copy the new Web page file to the shared Web site.

To create and copy an individual file

  1. In Solution Explorer, right-click the name of the Web site, and then click Add New Item.

  2. Under Visual Studio installed templates, click Web Form.

  3. In the Name box, type Extra.aspx.

  4. Click Add.

    You do not have to add any content to the page.

  5. Close the page.

    The new page is displayed in Source Web Site with arrows next to it pointing to Remote Web Site. If you synchronize right now, the files will be copied from the local Web site to the shared Web site.

  6. On the Copy Web tab, highlight to select the new page or pages.

  7. Click the right/left-arrow button to copy the selected files from the local Web site to the shared Web site.

    This button is not labeled unless you move the pointer over it, in which case a ToolTip appears.

    The new page is copied to the shared Web site and the list in Remote Web Site is updated.

Synchronizing Web Sites

Synchronizing means copying the most current version of each file so that both Web sites have the same copies of all files. Use synchronization, if the files on the shared Web site might be updated by someone other than you. In this part of the walkthrough, you will first change both the local and shared Web site, and then you will synchronize the changes between the sites.

To change the local and shared Web sites

  1. On the Copy <Websitename> tab, under Source Web site, click Extra.aspx, and then click the delete button.

  2. When prompted for confirmation to delete the file, click Yes.

    The files for the deleted page appear in Source Web Site with a symbol next to them, which indicates that the files have been deleted.

    Note

    Make sure that the Show deleted files since the last copy operation check box is selected.

  3. In Windows, start Notepad, and then open C:\SharedWebSite\Products.aspx.

  4. Add extra spaces or other characters to the file, save the file, and then close Notepad.

    You are changing the file to emulate what would occur if another developer changed the file on the shared Web site.

  5. In Visual Web Developer, on the Copy <Websitename> tab, click Refresh Remote Web Site.

    An arrow appears next to the Products.aspx file pointing to Source Web Site.

  6. Under Remote Web Site, highlight to select all files and folders, and then click the synchronize button to synchronize the selected file between the same relative paths in both LocalWebSite and SharedWebSite.

    This button is not labeled unless you move the pointer over it. The button has a right and left arrow to indicate both panes.

  7. When prompted to delete the Extra.aspx file in the remote Web site, which in effect is propagating the deletion to the remote Web site, click Yes.

    The Products.aspx page is copied from the remote Web site to the source Web site.

    Note

    If you selected all files and folders under Source Web Site and synchronized the files and folders, the results would be the same.

Next Steps

This walkthrough has illustrated the basic tasks that you can accomplish with the Copy Web Site tool. Although the Web sites that you worked with contained only a few files, you can apply the techniques that are used in this walkthrough to sites of any size. You might also want to experiment with additional ways to copy files to remote computers. For example, you might want to do the following:

See Also

Concepts

Copying Web Sites with the Copy Web Site Tool

Other Resources

Web Site Deployment in Visual Web Developer