Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Path.GetFullPath Method

Returns the absolute path for the specified path string.

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)

public static string GetFullPath (
	string path
)
public static String GetFullPath (
	String path
)
public static function GetFullPath (
	path : String
) : String
Not applicable.

Parameters

path

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

Return Value

A string containing the fully qualified location of path, such as "C:\MyFile.txt".

Exception typeCondition

ArgumentException

path is a zero-length string, contains only white space, or contains one or more of the invalid characters defined in GetInvalidPathChars.

-or-

The system could not retrieve the absolute path.

SecurityException

The caller does not have the required permissions.

ArgumentNullException

path is a null reference (Nothing in Visual Basic).

NotSupportedException

path contains a colon (":") that is not part of a volume identifier (for example, "c:\").

PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

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 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.

The following code example demonstrates the GetFullPath method on a Windows-based desktop platform.

string fileName = "myfile.ext";
string path1 = @"mydir";
string path2 = @"\mydir";
string fullPath;

fullPath = Path.GetFullPath(path1);
Console.WriteLine("GetFullPath('{0}') returns '{1}'", 
    path1, fullPath);

fullPath = Path.GetFullPath(fileName);
Console.WriteLine("GetFullPath('{0}') returns '{1}'", 
    fileName, fullPath);

fullPath = Path.GetFullPath(path2);
Console.WriteLine("GetFullPath('{0}') returns '{1}'", 
    path2, fullPath);

// Output is based on your current directory, except
// in the last case, where it is based on the root drive
// GetFullPath('mydir') returns 'C:\temp\Demo\mydir'
// GetFullPath('myfile.ext') returns 'C:\temp\Demo\myfile.ext'
// GetFullPath('\mydir') returns 'C:\mydir'

String fileName = "myfile.ext";
String path = "\\mydir\\";
String fullPath;

fullPath = Path.GetFullPath(path);
Console.WriteLine("GetFullPath('{0}') returns '{1}'", 
    path, fullPath);

fullPath = Path.GetFullPath(fileName);
Console.WriteLine("GetFullPath('{0}') returns '{1}'", 
    fileName, fullPath);

var fileName : String = "myfile.ext";
var path : String = "\\mydir\\";
var fullPath : String;

fullPath = Path.GetFullPath(path);
Console.WriteLine("GetFullPath('{0}') returns '{1}'", 
                  path, fullPath);

fullPath = Path.GetFullPath(fileName);
Console.WriteLine("GetFullPath('{0}') returns '{1}'", 
                  fileName, fullPath);

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

Show:
© 2014 Microsoft