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

  • SEARCH
  • Home
  • 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 8514973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:00:52+00:00 2026-06-11T05:00:52+00:00

I get a List<string> of files via recursion through FileFinderEx via win32 api (DllImport

  • 0

I get a List<string> of files via recursion through FileFinderEx via win32 api (DllImport of kernel32). (There’s several questions that go over how this is done).

I handle fully qualified paths greater than MAX_PATH by using \\?\UNC\ and \\?\.

Also, from win32 api I can grab the “short path” (8.3 name) of file via GetShortPathNameW.

Now that I have the List<string> of fully qualified paths to files, I want to iterate over each path and place their SHA256 into another list (same index). So roughly, something like this:

List<string> files = new List<string>();
//win api function populates files ...
List<string> hash = new List<string>();
for (int i = 0; i < files.Count; i++)
{
    using (var stream = new BufferedStream(File.OpenRead(files[i]), 1200000))
    {
        SHA256Managed sha = new SHA256Managed();
        byte[] checksum = sha.ComputeHash(stream);
        hash.Add(BitConverter.ToString(checksum).Replace("-", String.Empty));
        stream.Close();
    }
}

The problem I face is even if I give it the “short path” (8.3 name) the File.OpenRead always throws exception if the fully qualified UNC name is greater than MAX_PATH (260 I believe).

So… now what? Is there some win32 api function I can import to do the reading instead of File.OpenRead? Or is there some other .NET method to open files with long file paths? Any tips to get around this limitation?

  • 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-06-11T05:00:54+00:00Added an answer on June 11, 2026 at 5:00 am

    Take a look at the CreateFile function in kernel32.dll. Despite it’s name, you can use it to either read or create a file, and the Unicode version will allow you to use paths longer than MAX_PATH.

    [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
    internal static extern SafeFileHandle CreateFile(
        string lpFileName,
        EFileAccess dwDesiredAccess,
        EFileShare dwShareMode,
        IntPtr lpSecurityAttributes,
        ECreationDisposition dwCreationDisposition,
        EFileAttributes dwFlagsAndAttributes,
        IntPtr hTemplateFile);
    

    There is a good series of posts (part 1 here) on the BCL Team’s blog from a few years back covering the topic of long paths in Windows and .NET, which I think you’d find useful.

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

Sidebar

Related Questions

I have this List<string> . How to get certain strings via LINQ? I guessed
I'm attempting to do a simple bubble sort code to get familiar with list/string
I have a List<List<String>> I need to get a List of all possible concatenation
I need to get string array or list with ajax and Action, this is
Beside query string root folder how do i get the current doc library list(ListName)
When I enter a string that it not in the list, I get this
Public class AbcViewModel { public string native{get; set;} public string other{get; set;} public List<AbcViewModel>
I've got two List<Name> s: public class Name { public string NameText {get;set;} public
I have a collection like this List<int> {1,15,17,8,3}; how to get a flat string
I am able to get the list of network printers via this code: private

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.