Handling long file paths (over 260 characters) requires different approaches in
.NET Framework vs .NET Core due to historical limitations.
Why the 260 Character Limit?
Windows historically imposed a MAX_PATH limit of 260 characters. In .NET Framework, this limit is enforced unless you use special workarounds. .NET Core and .NET 5+ have better support for long paths by default.
.NET Framework (≤ 4.6.2)
Problem:
By default, paths longer than 260 characters cause an error like:
System.IO.PathTooLongException
Workaround:
Use UNC (long path) prefix: \\?\ before absolute paths.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Handling long file paths (over 260 characters) requires different approaches in .NET Framework vs .NET Core due to historical limitations.
Why the 260 Character Limit?
Windows historically imposed a
MAX_PATHlimit of 260 characters. In .NET Framework, this limit is enforced unless you use special workarounds. .NET Core and .NET 5+ have better support for long paths by default..NET Framework (≤ 4.6.2)
Problem:
By default, paths longer than 260 characters cause an error like:
Workaround:
Use UNC (long path) prefix:
\\?\before absolute paths.Requirements:
.NET Core / .NET 5+ / .NET 6+
.NET Core and .NET 5+ fully support long paths without requiring
\\?\if the OS supports it and it's enabled.Ensure Windows long paths are enabled:
gpedit.mscComputer Configuration > Administrative Templates > System > FilesystemOr modify registry:
Then use normally:
Tips
.NET Coreor later for better long path support.Path.GetFullPath()to debug unexpected length problems.