GetFullPathName (kernel32)
Last changed: -213.34.49.75

.
Summary

C# Signature:

[DllImport("kernel32.dll")]
static extern uint GetFullPathName(string lpFileName, uint nBufferLength,
   [Out] StringBuilder lpBuffer, out StringBuilder lpFilePart);

VB.net Signature:

  <DllImport("kernel32.dll")> _
Shared Function GetFullPathName(ByVal lpFileName As String, ByVal nBufferLength As Int32, <Out()> ByVal lpBuffer As System.Text.StringBuilder, <Out()> ByVal lpFilePart As System.Text.StringBuilder) As Int32

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

C# Sample

int bufsz = 1;                            // We'll grow this as necessary
string sRel = @"c:\windows\System\..\system32\desktop.ini";       // Note relative path
StringBuilder sbFull = new StringBuilder(bufsz);          // Full resolved path will go here
StringBuilder sbFile = new StringBuilder(bufsz);          // Filename will go here
uint u = GetFullPathName(sRel, (uint)bufsz, sbFull, out sbFile);  // 1st call: Get necessary bufsz
if (u > bufsz)                            // 'u' should be >1
{
   bufsz = (int)u + 10;                       // Required size plus a few
   sbFull = new StringBuilder(bufsz);                 // Re-create objects w/ proper size
   sbFile = new StringBuilder(bufsz);                 // "
   u = GetFullPathName(sRel, (uint)bufsz, sbFull, out sbFile);    // Try again, this should succeed
   // 'sbFull' should now contain "c:\windows\system32\desktop.ini"
   //    and 'sbFile' should contain "desktop.ini"
}

Alternative Managed API:

System.IO.FileSystemInfo.FullName or System.IO.Path.GetFullPath.

Documentation