Path.GetFullPath Method
Assembly: mscorlib (in mscorlib.dll)
| Exception type | Condition |
|---|---|
| path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars, or contains a wildcard character. -or- The system could not retrieve the absolute path. |
|
| The caller does not have the required permissions. |
|
| path is a null reference (Nothing in Visual Basic). |
|
| path contains a colon (":"). |
|
| 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 not 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 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. | |
| Write to a text file. | |
| Read from a text file. | |
| Retrieve a file extension. | |
| Retrieve only the file name from a path. | |
| Retrieve only the directory name from a path. | |
| Change the extension of a file. | |
| Sort files in a directory by size. | |
| Determine if a directory exists. | |
| Determine if a file exists. |
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);
- FileIOPermission for access to the path. Associated enumeration: FileIOPermissionAccess.PathDiscovery
Windows 98, Windows 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Reference
Path ClassPath Members
System.IO Namespace
Other Resources
File and Stream I/OHow to: Read Text from a File
How to: Write Text to a File