Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Paste Directorie(s) from clipboard

$
0
0

Hi im making a file explorer control and I'm having trouble with pasting a directory. My Copy function does however does copy directories. I tested this out by going to desktop and clicking paste.

Copy Function(C#)

StringCollection paths = new StringCollection();
paths.Add(selectedDirectory);
Clipboard.SetFileDropList(paths);

I did find some examples on pasting directors by different means. This would work but I want to use Clipboard so I can copy files outside my program and paste them inside my program and vise versa. I have pasting Files working.

Paste Function(C#)

foreach (string file in Clipboard.GetFileDropList())
{
	var fileExtension = Path.GetExtension(file);
        if (fileExtension != "")
        {
        	try
                {
                 File.Copy(file, selectedDirectory + "\\" + Path.GetFileName(file));
                 TreeNode treeNode = new TreeNode(Path.GetFileName(file));
                 treeNode.ImageIndex = treeNode.SelectedImageIndex = 2;
                 if (splitContainer.Panel2Collapsed)
                     treeView.SelectedNode.Nodes.Add(treeNode);
                 PopulateListView();
                 }
                 catch (SystemException e)
                 {
                     MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
	}
        else
        {

        }
}

I looked at the functions under clipboard but they don't seem to have anything for directories.

Thanks




Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>