dotnet / dotnet/dotnet-api-docs

Path.GetRelativePath forward slash or backslash

Open
#11,826 2 comments 0 reactions 0 assignees View on GitHub
area-System.IO untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

### Type of issue

Other (describe below)

### Description

In the examples for Path.GetRelativePath, there is the following:

```
[…]
Console.WriteLine(Path.GetRelativePath("C:/Program Files/Common Files", "C:/Program Files/Microsoft"));
[…]
// This code produces output similar to the following:
//
// ../Microsoft
[…]
```

In other words, it's saying that the output will use a forward slash, at least if the inputs to the function uses forward slashes (on Windows, since those are clearly Windows paths). However when running that myself on Windows I get `..\Microsoft`, contradicting the example code.

This means e.g. that this does not work on Windows: https://stackoverflow.com/a/66877016, as there will be `..\` instead of `../`, whereas that code would work if Path.GetRelativePath gave results like what is written in the example code.

### Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.io.path.getrelativepath?view=net-8.0

### Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.IO/Path.xml

### Document Version Independent Id

96559f6f-99cb-6994-6dde-7fcae426fe46

### Platform Id

85c93c86-ec19-1615-1f5b-76ab8e1e089a

### Article author

@dotnet-bot

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.