This documentation is archived and is not being maintained.

Path.Combine Method (String, String)

Combines two strings into a path.

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

static member Combine : 
        path1:string * 
        path2:string -> string 


Type: System.String
The first path to combine.
Type: System.String
The second path to combine.

Return Value

Type: System.String
The combined paths. If one of the specified paths is a zero-length string, this method returns the other path. If path2 contains an absolute path, this method returns path2.


path1 or path2 contains one or more of the invalid characters defined in GetInvalidPathChars.


path1 or path2 is a null reference (Nothing in Visual Basic).

If path1 is not a drive reference (that is, "C:" or "D:") and does not end with a valid separator character as defined in DirectorySeparatorChar, AltDirectorySeparatorChar, or VolumeSeparatorChar, DirectorySeparatorChar is appended to path1 before concatenation.

If path2 does not include a root (for example, if path2 does not start with a separator character or a drive specification), the result is a concatenation of the two paths, with an intervening separator character. If path2 includes a root, path2 is returned.

The parameters are not parsed if they have white space. Therefore, if path2 includes white space (for example, " c:\\ "), the Combine method appends path2 to path1 instead of returning only path2.

Not all invalid characters for directory and file names are interpreted as unacceptable by the Combine method, because you can use these characters for search wildcard characters. For example, while Path.Combine("c:\\", "*.txt") might be invalid if you were to create a file from it, it is valid as a search string. It is therefore successfully interpreted by the Combine method.

For a list of common I/O tasks, see Common I/O Tasks.

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

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.