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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:17:17+00:00 2026-05-15T10:17:17+00:00

I have so many issues with my project, i really don’t know where to

  • 0

I have so many issues with my project, i really don’t know where to begin. First off, i get an error “an object reference is required for non-static field, method or property”. It underlines retPath (the line: DriveRecursion_results.DriveRecursion(retPath);). I have no idea how to fix this.

THe other thing i’m still stumped on is how to populate a listview on my Windows Form. What i want is a list of files that need to be renamed (versus a list of all files in my list.)

Can anybody help? I have been struggling miserably with this for several hours now.

Here is my code:

Form1.cs:

namespace FileMigration
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

    }

    private void button1_Click(object sender, EventArgs e)
    {
        FolderSelect("Please select:");
    }
    public string FolderSelect(string txtPrompt)
    {
        //Value to be returned
        string result = string.Empty;

        //Now, we want to use the path information to population our folder selection initial location
        string initialCheckoutPathDir = (@"C:\");
        System.IO.DirectoryInfo info = new System.IO.DirectoryInfo(initialCheckoutPathDir);
        FolderBrowserDialog FolderSelect = new FolderBrowserDialog();
        FolderSelect.SelectedPath = info.FullName;
        FolderSelect.Description = txtPrompt;
        FolderSelect.ShowNewFolderButton = true;

        if (FolderSelect.ShowDialog() == DialogResult.OK)
        {
            string retPath = FolderSelect.SelectedPath;
            if (retPath == null)
            {
                retPath = "";
              }
            DriveRecursion_Results ds = new DriveRecursion_Results();
           ds(retPath);
            result = retPath;
            //Close this form.

        } 
        return result;
    }



   }
}

Here is DriveRecursion_Results.cs:

namespace FileMigration
{
public partial class DriveRecursion_Results : Form
{
    public DriveRecursion_Results()
    {
        InitializeComponent();
    }

    private void fileOutput_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    public void DriveRecursion(string retPath)
    {

       // string[] files = Directory.GetFiles(retPath, "*.*", SearchOption.AllDirectories);

        string pattern = " *[\\~#%&*{}/<>?|\"-]+ *";
        string replacement = "";
        Regex regEx = new Regex(pattern);

        string[] fileDrive = Directory.GetFiles(retPath, "*.*", SearchOption.AllDirectories);
        List<string> filePath = new List<string>();

        foreach (string fileNames in fileDrive)
        {
            if (regEx.IsMatch(fileNames))
            {
                filePath.Add(fileNames);
                //I tried adding my listview (fileOptions) here but I cannot for some reason
            }
        }

        }





        }




    }

ANY help would really be appreciated 🙁 Does anybody have any ideas on how to change my code so it actually works?

  • 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-15T10:17:17+00:00Added an answer on May 15, 2026 at 10:17 am

    You are not able to add items to your list view because you are trying to add them from a static method.

    Since it is static there is no ListView because there isn’t actually a Form to add things to. You will need to make DriveRecursion() not static in order to add things to the ListView.

    Additionally, when you make DriveRecursion() not static, you will need a way to let Form1 know which DriveRecursion_Results class to populate.

    Another approach you could take is having Form1 return retPath to DriveRecursion_Results.

    Edit

    Removed irrelevant parts of my original answer

    I have copied your code exactly how you posted it. And then made the following changes to FolderSelect() in Form1.cs When I run this code. I can get the second window to pop up, but not the other window to close, because that will cause the application to quit.

    Please make sure you have ds.Show() and do at some point call ds.DriveRecursion(retPath)

    Modified FolderSelect(string) in Form1.cs:

        private void FolderSelect( string txtPrompt )
        {
            //Value to be returned
            string result = string.Empty;
    
            //Now, we want to use the path information to population our folder selection initial location
            string initialCheckoutPathDir = ( "C:\\" );
            System.IO.DirectoryInfo info = new System.IO.DirectoryInfo( initialCheckoutPathDir );
            FolderBrowserDialog FolderSelect = new FolderBrowserDialog();
            FolderSelect.SelectedPath = info.FullName;
            FolderSelect.Description = txtPrompt;
            FolderSelect.ShowNewFolderButton = true;
    
            if( FolderSelect.ShowDialog() == DialogResult.OK )
            {
                string retPath = FolderSelect.SelectedPath;
                if( retPath == null )
                {
                    retPath = "";
                }
                DriveRecursion_Results ds = new DriveRecursion_Results();
                ds.DriveRecursion( retPath );
                ds.Show();
                result = retPath;
                //Close this form.
    
            }
            return;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok this is a really annoying bug that I have been having issues with
First to tell you i am really new to WPF I have some Question
I have recreated this project in Eclipse as many ways as I can think
Long story coming up, but I'll try to keep it brief. I have many
I'm having (many, but for now,) one problem with a project I'm working on.
Here's the question first: Is this possible? I'm taking my inspiration from Joe Wrobel's
We use Oracle on a project and would like to also support MySQL. How
Okay, so yesterday I managed to get the latest trunk builds of NHibernate and
I have a web site I am building for a client. I now have
I guess I haven't really had to do this much before because I am

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.