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 7993051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:44:21+00:00 2026-06-04T13:44:21+00:00

i got a big problem , alright so here is the problem : I

  • 0

i got a big problem , alright so here is the problem :
I am trying to get the fileinfo from a directory so that i can list it on listview .
When i recursively search for files using that method :

    private void Get_Files(string path)
    {
        DirectoryInfo di = new DirectoryInfo(path);

        FileInfo[] fi = di.GetFiles();

        foreach (FileInfo Info in fi)
        {
            try
            {
                Files.Add(Info.FullName);
            }
            catch(Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }

        foreach (DirectoryInfo DInfo in di.GetDirectories())
        {
            Get_Files(DInfo.FullName);
        }
    }

Sometimes the path is longer than 260 Characters , so i am getting that error :
Path is too long and it should not exceed 260 Characters , i have searched over the internet and people said that it has no solution , but i have figured out a solution my self .
Solution : is creating a string and appending each path of the path to that string , so i never get that error when saving the whole path into string.
Think of it as taking the path apart and taking each piece and appending it to the string.
So here is the solution i figured :

    List<string> Files = new List<string>();

    string completepath = string.Empty;
    string current_dire_name = string.Empty;

    private void Get_Files(string path)
    {
        DirectoryInfo di = new DirectoryInfo(path);

        FileInfo[] fi = di.GetFiles();

        foreach (FileInfo Info in fi)
        {
            try
            {
                completepath += "\\" + Info.Name;
                Files.Add(completepath);
                string remove_file_name = completepath;
                remove_file_name = remove_file_name.Replace("\\" + Info.Name, "");
                completepath = remove_file_name;
            }
            catch(Exception ee)
            {   
                if(DialogResult.Yes == MessageBox.Show("Error at the Get_Files Method and Error message :\n\n" + ee.Message + "\n\nQuit Application now ?","",MessageBoxButtons.YesNo,MessageBoxIcon.Question))
                {
                    Environment.Exit(0);
                }
            }
        }

        foreach (DirectoryInfo DInfo in di.GetDirectories())
        {
            string remove_folder_name = completepath;
            remove_folder_name = remove_folder_name.Replace("\\" + current_dire_name, "");
            completepath = remove_folder_name;

            current_dire_name = DInfo.Name;
            completepath += "\\" + DInfo.Name;
            Get_Files(DInfo.FullName);
        }
    }

Okay , that method saved me , but it generated wrong path , i mean something is not correct , lets say if path should be : C:\Folder1\Folder2\Folder3\file.txt
The generated path is : C:\Folder1\file.txt , something like that ….
I know that the method i did has something wrong especially the recursive appending.

I hope someone figure it with me , so that people can avoid the long path exception.

  • 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-04T13:44:23+00:00Added an answer on June 4, 2026 at 1:44 pm

    You’re looking for the .Net Long Path library, which uses the \\?\ prefix with the Windows APIs to avoid the restriction entirely.

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

Sidebar

Related Questions

I've got a big problem, I can't launch anything from the terminal, not python,
I have got very big problem because I would like to get more information
here i am again :( got big problem hiks ... need HELP !!! i
I've a litle big problem with java heap memory I'm trying to migrate from
i've got a big Problem and i was trying the whole day and did
I got a serious problem here: I have a scrolling background that is 1320
Got a big problem here which killed my whole day... I cant fix it
I got a big problem, I used Lazy load of images in ListView to
I've got a big problem with IBM HACL for accessing a server which speaks
I've got a big multi-module project, and I'd like to generate a report that

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.