O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Set the Current Working Path

Problem

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

Solution

Use the shared Directory.GetCurrentDirectory and Directory.SetCurrentDirectory methods.

Discussion

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

Here’s a simple test that demonstrates these concepts:

Console.WriteLine("Using: " & Directory.GetCurrentDirectory()) Console.Write("The relative path ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required