Managing your Project Files

When you edit an HTML template file, save your project, or debug the application, Visual Basic saves the webclass and its associated template .htm files to the directory you specify. When you debug the project, Visual Basic uses this directory as the IIS virtual directory the webclass needs to run. A virtual directory is a directory outside your Web server's home directory that appears to browsers as a subdirectory of the home directory. A virtual directory allows you to publish contents to the Web from directories outside the home directory structure.

Note   All of the project files — including the designer and any files the templates reference — should be located either in the project directory or in a subdirectory beneath it. The .htm files for the templates must be in the main project directory.

You can think of your project directory for an IIS application as a "mirror" of the directory structure you will use on the Web server when you deploy the application. You should arrange the files for your project in the directory structure you plan to use. For example, if you plan to use a separate graphics directory on the Web server, you should use a similar subdirectory beneath your project directory.

Relative vs. Absolute URL Paths

After you link a template file to a webclass, you must make sure that the references it contains to images and other files will work correctly when you deploy your application to the server. In most cases, you can ensure this by using relative paths in the URLs that reference these images and other files.

For example, suppose you have an HTML page that references two images on your local drive, using absolute URLs — that is, URL paths that indicate the drive and directory in which to find an associated file. When you deploy the template file to the Web, these references are no longer valid. Instead, you should replace these absolute references with relative URLs — that is, URL paths that indicate the location of an item relative to the current directory, without giving a specific drive or root directory. As long as the directory structure you use on your development computer mimics the directory structure you use on the Web site, your links will resolve correctly after deployment.

There are two situations in which you can safely use absolute URL paths:

Example:  Setting Up Directories for a Simple Webclass

Suppose you have a project called feedback.vbp. The webclass in this project uses a single template file:  thankyou.htm. This HTML page references two image files: a corporate logo called logo.gif and a decorative picture called banner.gif. The following table shows the original locations of the files in this project:

File Original Location
feedback.vbp c:\vb98\myproject\
thankyou.htm c:\front page\
logo.gif c:\front page\images\
banner.gif c:\front page\images\

After you add the template to the webclass and save the project, Visual Basic creates a copy of the HTML page and stores it in the project directory. The following table shows the changes to your directory structure after adding the template. These changes happen automatically when you add the template.

File Interim Location
feedback.vbp c:\vb98\myproject\
thankyou.htm c:\vb98\myproject\
logo.gif c:\front page\images\
banner.gif c:\front page\images\

The final step is to move the .gif files into the project directory or a subdirectory beneath it. Suppose you plan to use a separate graphics directory on the Web server to contain your images. You need to use this same structure on your development computer, so you would create a graphics subdirectory under c:\vb98\myproject\ for your images, then manually copy the files to that location. The following table shows the final directory structure for your file, before deployment. You would make these changes manually by copying the files to the project directory.

File Final Location
feedback.vbp c:\vb98\myproject\
thankyou.htm c:\vb98\myproject\
logo.gif c:\vb98\myproject\graphics\
banner.gif c:\vb98\myproject\graphics\

Example: Using Relative Paths

After copying the graphics files to the subdirectory as shown above, you  must make sure that your references to these images in the .htm file and in your Visual Basic code use relative paths that accurately reflect the files' location after deployment. For example, in the .htm file any references to the logo graphic should be:

images/logo.gif

This is considered a relative URL because it does not provide the full server and directory path to the file. Instead, it indicates that the file can be found in a graphics subdirectory of the Web server directory from which the current page was drawn.

For More Information   See the HTML reference of your choice for more information on relative and absolute paths.