Share via


Path.Combine Method (String, String)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

When it is called by trusted applications, combines two path strings.

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

Syntax

'Declaration
Public Shared Function Combine ( _
    path1 As String, _
    path2 As String _
) As String
public static string Combine(
    string path1,
    string path2
)

Parameters

Return Value

Type: System.String
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.

Exceptions

Exception Condition
ArgumentException

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

ArgumentNullException

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

Remarks

If path1 does not end with a valid separator character as defined in DirectorySeparatorChar or AltDirectorySeparatorChar, a 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.

Examples

The following example combines directory and subdirectory names into paths for creating the directories in isolated storage. This example is part of a larger example provided for the IsolatedStorageFile class.

' Create three subdirectories under MyApp1.
Dim subdirectory1 As String = Path.Combine("MyApp1", "SubDir1")
Dim subdirectory2 As String = Path.Combine("MyApp1", "SubDir2")
Dim subdirectory3 As String = Path.Combine("MyApp1", "SubDir3")
store.CreateDirectory(subdirectory1)
store.CreateDirectory(subdirectory2)
store.CreateDirectory(subdirectory3)
// Create three subdirectories under MyApp1.
string subdirectory1 = Path.Combine("MyApp1", "SubDir1");
string subdirectory2 = Path.Combine("MyApp1", "SubDir2");
string subdirectory3 = Path.Combine("MyApp1", "SubDir3");
store.CreateDirectory(subdirectory1);
store.CreateDirectory(subdirectory2);
store.CreateDirectory(subdirectory3);

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.