The fully qualified location of path, such as "C:\MyFile.txt".
Type Reason 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.SecurityException The caller does not have the required permissions. ArgumentNullException path is null . System.IO.PathTooLongException The length of path or the absolute path information for path exceeds the system-defined maximum length.
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.
Type | Reason |
---|---|
System.Security.Permissions.FileIOPermission | Requires permission to access path information. See System.Security.Permissions.FileIOPermissionAccess.PathDiscovery . |
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