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.

[Visual Basic]
Public Shared Function GetFullPath( _
   ByVal path As String _
) As String
[C#]
public static string GetFullPath(
 string path
);
[C++]
public: static String* GetFullPath(
 String* path
);
[JScript]
public static function GetFullPath(
   path : String
) : String;

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

Exceptions

Exception Type Condition
ArgumentException path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.

-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 (":").
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.

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 Path class, this method accesses the file system.

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

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

For an example of using this method, see the Example section below. The following table lists examples of other typical or related I/O tasks.

To do this... See the example in this topic...
Create a text file. Writing Text to a File
Write to a text file. Writing Text to a File
Read from a text file. Reading Text from a File
Retrieve a file extension. GetExtension
Retrieve only the file name from a path. GetFileNameWithoutExtension
Retrieve only the directory name from a path. GetDirectoryName
Change the extension of a file. ChangeExtension
Sort files in a directory by size. GetFileSystemInfos
Determine if a directory exists. Exists
Determine if a file exists. Exists

Example

[Visual Basic, C#, C++] The following example demonstrates the GetFullPath method on a Windows-based desktop platform.

[Visual Basic] 
Dim fileName As String = "myfile.ext"
Dim pathname As String = "\mydir\"
Dim fullPath As String

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

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

[C#] 
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);

[C++] 
String * fileName = S"myfile.ext";
String * path = S"\\mydir\\";
String * fullPath;

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

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

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

.NET Framework Security: 

See Also

Path Class | Path Members | System.IO Namespace | Working with I/O | Reading Text from a File | Writing Text to a File

Show:
© 2014 Microsoft