Combine Method (String[])
Collapse the table of content
Expand the table of content

Path.Combine Method (String[])

 

Combines an array of strings into a path.

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

public static string Combine(
	params string[] paths
)

Parameters

paths
Type: System.String[]

An array of parts of the path.

Return Value

Type: System.String

The combined paths.

Exception Condition
ArgumentException

One of the strings in the array contains one or more of the invalid characters defined in GetInvalidPathChars.

ArgumentNullException

One of the strings in the array is null.

paths should be an array of the parts of the path to combine. If the one of the subsequent paths is an absolute path, then the combine operation resets starting with that absolute path, discarding all previous combined paths.

Zero-length strings are omitted from the combined path.

The parameters are not parsed if they have white space.

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.

The following example combines an array of strings into a path.

string[] paths = {@"d:\archives", "2001", "media", "images"};
string fullPath = Path.Combine(paths);
Console.WriteLine(fullPath);

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 4.0
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2016 Microsoft