<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/howto-using-path-combine-correctly-to-ensure-cross-platform-compatibility-rild2yaer" -->

---
title: [HOWTO] Using Path.Combine correctly to ensure...
description: A common mistake when using .NET's Path.Combine method is hardcoding Windows-style backslash path segments like "..\..\..\..\ArbitraryDirectory" as a single...
canonical: https://daily.dev/posts/howto-using-path-combine-correctly-to-ensure-cross-platform-compatibility-rild2yaer
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: [HOWTO] Using Path.Combine correctly to ensure cross-platform compatibility | daily.dev
og:description: A common mistake when using .NET's Path.Combine method is hardcoding Windows-style backslash path segments like "..\..\..\..\ArbitraryDirectory" as a single...
og:url: https://daily.dev/posts/howto-using-path-combine-correctly-to-ensure-cross-platform-compatibility-rild2yaer
og:image: https://api.daily.dev/og/posts/RIlD2yaER.png
og:image:alt: [HOWTO] Using Path.Combine correctly to ensure cross-platform compatibility
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# [HOWTO] Using Path.Combine correctly to ensure cross-platform compatibility

**[We Are .NET](https://daily.dev/sources/wearedotnet)** · 1 min read · 0 upvotes · 0 comments

## Summary

A common mistake when using .NET's Path.Combine method is hardcoding Windows-style backslash path segments like "..\..\..\..\ArbitraryDirectory" as a single string argument. This works on Windows but throws a DirectoryNotFoundException on Linux because the backslashes aren't recognized as separators. The fix is to pass each path segment as a separate string argument to Path.Combine (e.g., "..", "..", "..", "..", "ArbitraryDirectory"), letting the method choose the correct delimiter for the underlying operating system.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://blog.rufer.be/2026/08/24/howto-using-path-combine-correctly-to-ensure-cross-platform-compatibility>

## Questions this post answers

### Why does my Path.Combine code with hardcoded backslashes work on Windows but throw a DirectoryNotFoundException on Linux?

Hardcoding relative path segments as a single string like "..\..\..\..\ArbitraryDirectory" embeds Windows-style backslashes, which Linux does not interpret as directory separators, causing a DirectoryNotFoundException. Instead, pass each segment as a separate argument to Path.Combine, e.g. Path.Combine(AppContext.BaseDirectory, "..", "..", "..", "..", "ArbitraryDirectory"), so the method inserts the correct separator for the current OS.

_daily.dev surfaces practical .NET fixes like this for developers hardening cross-platform path handling._

## Similar posts on daily.dev

- [Off the Path](https://daily.dev/posts/off-the-path-hdds0umvq) · The Daily WTF · 2 upvotes · 0 comments
- [Windows has been silently breaking file paths for decades, and the fix is one Group Policy toggle away](https://daily.dev/posts/windows-has-been-silently-breaking-file-paths-for-decades-and-the-fix-is-one-group-policy-toggle-aw-uogrcshf1) · XDA Developers · 0 upvotes · 0 comments
- [Reserved filenames on Windows \(CON, PRN, AUX, NUL...\)](https://daily.dev/posts/reserved-filenames-on-windows-con-prn-aux-nul--g6erwk7l2) · Meziantou · 1 upvotes · 0 comments
- [The Destination Dir](https://daily.dev/posts/the-destination-dir-qrscglp6r) · The Daily WTF · 1 upvotes · 0 comments

---

Tags: [#.net](https://daily.dev/tags/.net), [#c#](https://daily.dev/tags/c#)

[View this post on daily.dev](https://daily.dev/posts/howto-using-path-combine-correctly-to-ensure-cross-platform-compatibility-rild2yaer)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"[HOWTO] Using Path.Combine correctly to ensure cross-platform compatibility","url":"https://daily.dev/posts/howto-using-path-combine-correctly-to-ensure-cross-platform-compatibility-rild2yaer","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/howto-using-path-combine-correctly-to-ensure-cross-platform-compatibility-rild2yaer"},"datePublished":"2026-08-24T07:01:50.969Z","dateModified":"2026-09-14T07:06:38.734Z","description":"A common mistake when using .NET's Path.Combine method is hardcoding Windows-style backslash path segments like \"..\\..\\..\\..\\ArbitraryDirectory\" as a single...","image":"https://media.daily.dev/image/upload/s--HRgLpUt6--/f_auto/v1722860399/public/Placeholder%2003","thumbnailUrl":"https://media.daily.dev/image/upload/s--HRgLpUt6--/f_auto/v1722860399/public/Placeholder%2003","isAccessibleForFree":true,"articleSection":"We Are .NET","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"We Are .NET","logo":"https://media.daily.dev/image/upload/s--BsnVOa3i--/f_auto/v1718347410/logos/wearedotnet","url":"https://daily.dev/sources/wearedotnet"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/howto-using-path-combine-correctly-to-ensure-cross-platform-compatibility-rild2yaer","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":".net,c#","timeRequired":"PT1M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"We Are .NET","item":"https://daily.dev/sources/wearedotnet"},{"@type":"ListItem","position":3,"name":"[HOWTO] Using Path.Combine correctly to ensure cross-platform compatibility"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/howto-using-path-combine-correctly-to-ensure-cross-platform-compatibility-rild2yaer#faq","mainEntity":[{"@type":"Question","name":"Why does my Path.Combine code with hardcoded backslashes work on Windows but throw a DirectoryNotFoundException on Linux?","acceptedAnswer":{"@type":"Answer","text":"Hardcoding relative path segments as a single string like \"..\\..\\..\\..\\ArbitraryDirectory\" embeds Windows-style backslashes, which Linux does not interpret as directory separators, causing a DirectoryNotFoundException. Instead, pass each segment as a separate argument to Path.Combine, e.g. Path.Combine(AppContext.BaseDirectory, \"..\", \"..\", \"..\", \"..\", \"ArbitraryDirectory\"), so the method inserts the correct separator for the current OS. daily.dev surfaces practical .NET fixes like this for developers hardening cross-platform path handling."}}]}
```

