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

Manipulate a Filename

Problem

You want to retrieve a portion of a path or verify that a file path is in a normal (standardized) form.

Solution

Process the path using the System.IO.Path class.

Discussion

File paths are often difficult to work with in code because there are an unlimited number of ways to represent the same directory. For example, you might use an absolute path (c:\temp), a UNC path (\\myserver\\myshare\temp), or one of many possible relative paths (c:\ temp\ myfiles\..\ or c:\temp\myfiles\..\..\temp). This is especially the case if you want the user to supply a file or path value. In this case, the user could specify a relative path that points to an operating system file. If your code doesn’t detect the problem, sensitive information ...

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