Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4030242
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:26:48+00:00 2026-05-20T11:26:48+00:00

I’m working on an application which walks through every file in some directories and

  • 0

I’m working on an application which walks through every file in some directories and does some actions with those files. Among others, I must retrieve the file size and the date when this file was modified.

Some file full names (directory + file name) being too long, I couldn’t use .NET Framework FileInfo, which is limited to MAX_PATH (260 characters). Many web sources advised to use native Win32 functions through P/Invoke to access the files whose names are too long.

Currently, the exactly same problem seems to arise with Win32 functions. For example, GetFileAttributesEx (kernel32.dll) fails with Win32 error 3 ERROR_PATH_NOT_FOUND for the path of 270 bytes.

The very same file can successfully be opened from Notepad2 and successfully displayed with Windows Explorer (but Visual Studio 2010 for example fails to open it because of the 259 characters limit¹).

What can I do to be able to access a file when the file path is 270 characters long?

Notes:

  • Removing or ignoring files with the file path length longer than 259 characters is not a solution.

  • I’m looking for Unicode-compatible solutions only.

  • The application will run under Windows 2008/Vista or later with .NET Framework 4 installed.


¹ Surprisingly, Microsoft Word 2007 fails, complaining that “the floppy disk is too small” on a computer which don’t have any floppy drive, or that “RAM memory is low” when there is 4 GB of RAM left, or finally that “antivirus software […] needs to be updated”. Will they stop one day displaying such stupidly meaningless errors at least in such key products as Microsoft Office?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:26:49+00:00Added an answer on May 20, 2026 at 11:26 am

    .NET 4.6.2 Solution

    Use the \\?\C:\Verrrrrrrrrrrry long path syntax as described here.

    .NET Core Solution

    It just works because the framework adds the long path syntax for you.

    Pre .NET 4.6.2 Solution

    Also use the long path syntax and the Unicode version of the Win32 API function with P/Invoke.
    From Naming Files, Paths, and Namespaces:

    The Windows API has many functions that also have Unicode versions to permit an extended-length path for a maximum total path length of 32,767 characters. This type of path is composed of components separated by backslashes, each up to the value returned in the lpMaximumComponentLength parameter of the GetVolumeInformation function (this value is commonly 255 characters). To specify an extended-length path, use the \\?\ prefix. For example, \\?\D:\very long path.

    Reading this Microsoft Support page might also be interesting.

    A very extensive explanation in Long Paths in .NET by Kim Hamilton at the BCL Team blog lists a few hitches in handling these paths which he claims are the reason this syntax is still not supported in .NET directly:

    There are several reasons we were reluctant to add long paths in the past, and why we’re still careful about it <…>.

    <…> the \\?\ prefix not only enables long paths; it causes the path to be passed to the file system with minimal modification by the Windows APIs. A consequence is that \\?\ turns off file name normalization performed by Windows APIs, including removing trailing spaces, expanding ‘.’ and ‘..’, converting relative paths into full paths, and so on.<…>

    <…> Long paths with the \\?\ prefix can be used in most of the file-related Windows APIs, but not all Windows APIs. For example, LoadLibrary<…> fails if the file name is longer than MAX_PATH. <…> There are similar examples throughout the Windows APIs; some workarounds exist, but they are on a case-by-case basis.

    Another factor <…> is compatibility with other Windows-based applications and the Windows shell itself <…>

    Because this problem is becoming increasingly common <…> there are efforts throughout Microsoft to address it. In fact, as a timely Vista plug, you’ll notice a couple of changes that reduce the chance of hitting the MAX_PATH limit: many of the special folder names have shortened and, more interestingly, the shell is using an auto-path shrinking feature <…> to attempt to squeeze them into 260 characters.


    Warning: You might need to call the Windows APIs directly, since I think the .NET Framework might not support this kind of path syntax.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
Does anyone know how can I replace this 2 symbol below from the string
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.