. Updated Daily. Editions SDA India   SDA Indonesia
JAX Asia 2008 - Conference for Enterprise Java, SOA, Spring, Web Services, Ajax, Agile and more
BUSINESS ENTERPRISE SOLUTIONS ARCHITECTURE INFORMATION SECURITY WIRELESS & MOBILITY DATA & STORAGE DEVELOPMENT HARDWARE













News

Wednesday, 25 April 2007

Working with .NET Files Via the Path Class

 

 

Developers often need to know certain aspects of a file such as the name, full path, drive, and file extension. The .NET Framework provides easy access to these details via the Path class contained in the System.IO namespace. The article over at Builder.com by Tony Patton examines the various pieces of information available in the Path class with a focus on .NET Framework 2.0.

The Path class allows you to work with file path values. A key aspect of the class is the fact that it uses string values to perform all of its operations. This may not seem like a big deal, but the string may be an actual file name or a random string. You should utilise other classes, such as the File class, to confirm the existence of a file. The class provides various properties and methods to perform operations.

Many of the methods contained in the Path class accept a path as a parameter. A path is a string that provides the location of a file or directory. A path does not necessarily point to a location on disk. The exact format of a path is determined by the current platform. A path can refer to a file or just a directory. The specified path can also refer to a relative path or a Universal Naming Convention (UNC) path for a server and share name.
Weekly .NET tips in your inbox.

The following list provides a sampling of the methods available in the Path class:

  • ChangeExtension: allows you to change the file extension of a path string
  • Combines: allows you to combine two path strings into one
  • GetDirectoryName: returns the directory information included in a path string.
  • GetExtension: returns the extension included in a path string
  • GetFileName: returns the file name and extension of a path string.
  • GetFileNameWithoutExtension: returns the file name without the extension for a path string.
  • GetFullPath: returns the absolute path for a path string.
  • GetInvalidFileNameChars: returns a character array containing the characters not allowed in file names.
  • GetPathRoot: returns the root directory information for a path string.
  • GetRandomFileName: returns a random file or folder name.
  • GetTempFileName: a uniquely named, zero-byte temporary file is created with the full path returned.
  • GetTempPath: the path to the system's temporary directory is returned.
  • HasExtension: determines if a path string contains an extension (true) or not (false).
  • IsPathRooted: gets a value indicating whether the specified path string contains absolute or relative path information.

 

More Info

 
 
print save email comment

print

save

email

comment

 
 

Search SDA Asia

Free eNewsletter

SDA Asia Magazine Free Download
 
 
 
Copyright @ 2008 SDA Asia Magazine - All Right Reserved Privacy Policy | Terms of Use