System.IO.Path.GetFullPath Method

Returns the absolute path for the specified path string.

Syntax

public static string GetFullPath (string path)

Parameters

path
The file or directory for which to obtain absolute path information.

Returns

The fully qualified location of path, such as "C:\MyFile.txt".

Exceptions

TypeReason
ArgumentException

path is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters.

-or-

The system could not retrieve the absolute path.

System.Security.SecurityExceptionThe caller does not have the required permissions.
ArgumentNullException path is null .
System.IO.PathTooLongExceptionThe length of path or the absolute path information for path exceeds the system-defined maximum length.

Remarks

The .NET Framework does not support direct access to physical disks through paths that are device names, such as "\\.\PHYSICALDRIVE0 ".

The absolute path includes all information required to locate a file or directory on a system.

The file or directory specified by path is not required to exist. For example, if c:\temp\newdir is the current directory, calling GetFullPath on a file name such as test.txt returns c:\temp\newdir\test.txt. The file need not exist.

However, if path does exist, the caller must have permission to obtain path information for path. Note that unlike most members of the System.IO.Path class, this method accesses the file system.

This method uses current directory and current volume information to fully qualify path. If you specify a file name only in path, GetFullPath returns the fully qualified path of the current directory.

If you pass in a short file name, it is expanded to a long file name.

If a path contains no significant characters it is invalid unless it contains one or more "." characters followed by any number of spaces, then it will be parsed as either "." or "..".

For a list of common I/O tasks, see Common I/O Tasks.

Permissions

TypeReason
System.Security.Permissions.FileIOPermissionRequires permission to access path information. See System.Security.Permissions.FileIOPermissionAccess.PathDiscovery .

Example

The following example demonstrates the Path.GetFullPath(string) method on a Windows system. In this example, the absolute path for the current directory is c:\ecmatest\examples.

C# Example

using System; 
using System.IO; 
class GetDirectoryTest { 
 public static void Main() { 
   string [] paths = { 
     @"\ecmatest\examples\pathtests.txt", 
     @"\ecmatest\examples\", 
     "pathtests.xyzzy", 
     @"\", 
   }; 
   foreach (string pathString in paths) 
     Console.WriteLine("Path: {0} full path is {1}",pathString, 

Path.GetFullPath(pathString));
 } 
}

The output is

Path: \ecmatest\examples\pathtests.txt full path is C:\ecmatest\examples\pathtests.txt
Path: \ecmatest\examples\ full path is C:\ecmatest\examples\
Path: pathtests.xyzzy full path is C:\ecmatest\examples\pathtests.xyzzy
Path: \ full path is C:\

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0