Share via


Path.Combine Method

Combines two path strings.

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

Syntax

public static string Combine (
         stringpath1,
         stringpath2
)

Parameters

  • path1
    The first path.
  • path2
    The second path.

Return Value

A string containing 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.

Remarks

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.

Because the parameters are not parsed if they have white space, if path2 is " c:\\ ", this will be appended 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.

Version Information

Available in the .NET Micro Framework versions 3.0, 4.0, and 4.1.

See Also

Reference

Path Class
Path Members
System.IO Namespace