5.15. Work with Relative Paths

Problem

You want to set the current working directory so that you can use relative paths in your code.

Solution

Use the Shared GetCurrentDirectory and SetCurrentDirectory methods of the System.IO.Directory class.

How It Works

Relative paths are automatically interpreted in relation to the current working directory, which is the path of the current application by default. You can retrieve the current working directory by calling Directory.GetCurrentDirectory or change it using Directory.SetCurrentDirectory. In addition, you can use the Shared GetFullPath method of the System.IO.Path class to convert a relative path into an absolute path using the current working directory.

The Code

The following is a simple example ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.