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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:10:13+00:00 2026-05-29T10:10:13+00:00

im making a file explorer tool in c# .. im using ListView to explore

  • 0

im making a file explorer tool in c# .. im using ListView to explore files

but i have an issue when i copy items(files)

public ListView.SelectedListViewItemCollection copiedItems;

private void btnCopy_Click(object sender, EventArgs e)
    {
        copiedItems = listView1.SelectedItems;
        infoLabel.Text = "Item(s) copied to clipboard.";
    }

private void Paste()
    {
        if (copiedItems != null)
        {
            foreach (ListViewItem item in copiedItems)
            {
                if (File.Exists(item.ToolTipText))
                {
                    if (MessageBox.Show(item.ToolTipText + "is already exists\r\nDo you want to overwrite it?"
                    , "Overwrite", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK)
                    {
                        File.Copy(item.ToolTipText, currAddress, true);
                        infoLabel.Text = "Item(s) Pasted.";
                    }
                    return;
                }
                File.Copy(item.ToolTipText, currAddress, false);
                infoLabel.Text = "Item(s) Pasted.";
            }
        }
    }

when i change the folder that i am into(currAddress) .. the paste doesn’t work because the

 ListView.SelectedListViewItemCollection copiedItems 

changed to null. .. here’s my explorer code

private void DirRecursive(string path)
    {
            DirectoryInfo dir = new DirectoryInfo(path);
            currAddress = path;
            txtAddress.Text = path;
            _iconListManager.ClearLists();
            listView1.Items.Clear();
            foreach (DirectoryInfo folder in dir.GetDirectories())
                {
                    if ((folder.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                        continue;
                    ListViewItem item = new ListViewItem();
                    item.Text = folder.Name;
                    item.Tag = (object)folder.Parent;
                    item.ToolTipText = folder.FullName;
                    item.ImageIndex = _iconListManager.AddFolderIcon(folder.FullName);
                    listView1.Items.Add(item);
                }
                foreach (FileInfo file in dir.GetFiles())
                {
                    if ((file.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                        continue;
                    ListViewItem item = new ListViewItem();
                    item.Text = file.Name;
                    item.Tag = (object)file.Directory.Parent;
                    item.ToolTipText = file.FullName;
                    item.ImageIndex = _iconListManager.AddFileIcon(file.FullName);
                    item.SubItems.Add(CnvrtUnit(file.Length));
                    listView1.Items.Add(item);
                }

is there any explanation why copiedItems changed to null and how can i fix it ?

thanks in advance 🙂

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

    Instead of

    public ListView.SelectedListViewItemCollection copiedItems;
    

    use

    public List<string> copiedItems;
    

    Change btnCopy_Click to this:

    private void btnCopy_Click(object sender, EventArgs e)
        {
            copiedItems = listView1..SelectedItems.Cast<ListViewItem>().Select(li => li.ToolTipText).ToList();
            infoLabel.Text = "Item(s) copied to clipboard.";
        }
    

    change Paste to this:

    private void Paste()
        {
            if (copiedItems != null)
            {
                foreach (string item in copiedItems)
                {
                    if (File.Exists(item))
                    {
                        if (MessageBox.Show(item + "is already exists\r\nDo you want to overwrite it?"
                        , "Overwrite", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK)
                        {
                            File.Copy(item, currAddress, true);
                            infoLabel.Text = "Item(s) Pasted.";
                        }
                        return;
                    }
                    File.Copy(item, currAddress, false);
                    infoLabel.Text = "Item(s) Pasted.";
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a file edit interface in my web-app, I have a textarea with
I'm making a explorer like app to browse files stored on my computer. My
I have a habit of making file backups by adding the .bak extension (file.ext.bak).
I am having trouble making a file, I think I have got the majority
I am making a CSS file for an XML document. I need to insert
Is is possible to prevent Wget from making an output file when there is
I am making a litte php-file to log some ip addresses. It is going
I am making a POST to another php file that I want to render
I'm making a page where the user upload a file. I want an if
I'm making tests with ASP.NET HttpHandler for download a file writting directly on the

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.