472,779 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 software developers and data experts.

Distinguish between folder drop and file drop

I need to trigger some code when user drags and drops an entire folder onto
my form.

How can I distinguish between a folder drop and files dropped ? Can someone
point me to code or a sample, please ?

Thanks !
Oct 21 '06 #1
3 3187
hi silvester, can you paste some example code?... any way...
when you fire any event you must have an eventhandler object and a
sender object.
explore what you get at sender.ToString(), or typeOf(sender)...

maybe that helps, have a nice day...

Silvester ha escrito:
I need to trigger some code when user drags and drops an entire folder onto
my form.

How can I distinguish between a folder drop and files dropped ? Can someone
point me to code or a sample, please ?

Thanks !
Oct 21 '06 #2
MMA
You may want to start off by looking at the documentation on
FileSystemWatcher.OnCreated

One way to diffrentiate betweeb a file or folder is created/copied to your
watching folder

You may first try to open the newly created object with System.IO.File if
that throws an exception it should indicate that is not a file. Than attempt
opening the same object with System.IO.Directory. If either of these 2
attempts fails should be an indicationg it neither a file nor a dir.

Hope this helps.

"Silvester" wrote:
I need to trigger some code when user drags and drops an entire folder onto
my form.

How can I distinguish between a folder drop and files dropped ? Can someone
point me to code or a sample, please ?

Thanks !
Oct 21 '06 #3
Silvester wrote:
I need to trigger some code when user drags and drops an entire folder onto
my form.

How can I distinguish between a folder drop and files dropped ? Can someone
point me to code or a sample, please ?

Thanks !

If I understand it right, the folders will be dragged onto your form
from the windows explorer. Then the yode below should give you a good start:

using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;

namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnDragOver(DragEventArgs drgevent)
{
ICollection<stringfiles = new List<string>();
ICollection<stringfolders = new List<string>();
ExtractDragDropData(drgevent, files, folders);

// is it file/folder d&d?
if (files.Count == 0 && folders.Count == 0)
return;

// Set D&D cursor depending on what is inside the d&d data
if (files.Count 0)
drgevent.Effect = DragDropEffects.Move;
else if (folders.Count 0)
drgevent.Effect = DragDropEffects.Copy;

base.OnDragOver(drgevent);
}

private static void ExtractDragDropData(DragEventArgs drgevent,
ICollection<stringfiles, ICollection<stringfolders)
{
foreach (string fileOrFolder in
(string[])drgevent.Data.GetData("FileDrop"))
{
if (Directory.Exists(fileOrFolder))
folders.Add(fileOrFolder);
else if(File.Exists(fileOrFolder))
files.Add(fileOrFolder);
else
{
// Something completely diferent
}
}
}

protected override void OnDragDrop(DragEventArgs drgevent)
{
ICollection<stringfiles = new List<string>();
ICollection<stringfolders = new List<string>();
ExtractDragDropData(drgevent, files, folders);

MessageBox.Show(string.Format("You have dropped {0} files
and {1} folders", files.Count, folders.Count));
base.OnDragDrop(drgevent);
}
}
}
HTH,
Andy
--
You can email me directly by removing the NOSPAm below
xm**********@gmxNOSPAm.netNOSPAm
Oct 23 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jon Maz | last post by:
Hi there, I am experimenting with the FileSystemWatcher object. I have set the NotifyFilter as follows: myFileSystemWatcher.NotifyFilter = NotifyFilters.Security | NotifyFilters.CreationTime...
2
by: pradeep_TP | last post by:
Hello, I am trying to use APP_CODE folder for all my class files under VS 2005. After adding APP_CODE in the solution explorer, I added a new web page by right clicking project and selecting add...
2
by: jonathan184 | last post by:
how to move one file at a time to another folder. I am trying to one file at a time for every 30 minutes. So far the script is transferring all files at the same time and the source folder...
1
by: Larry Bates | last post by:
I have a need to implement a drop folder upload mechanism for secure uploading of files to a server. At first glance this appears that it would be an easy application to write. Then I begin to...
5
by: Noozer | last post by:
I'm looking for a "smart folder" program to run on my Windows XP machine. I'm not having any luck finding it and think the logic behind the program is pretty simple, but I'm not sure how I'd...
0
by: Mailing List SVR | last post by:
Hi, is there a simple way to do this? ftplib seems unable to distinguish between files and dir, a mimetype check would be good, regards Nicola
0
by: Fredrik Lundh | last post by:
Mailing List SVR wrote: the FTP protocol doesn't specify the format for the output from the LIST command, so you have to use some heuristics; see e.g. the code in ...
9
by: Keith G Hicks | last post by:
I'm having a lot of trouble with "file in use" errors in my "folder watcher" project. Starting and stopping the watcher and reading my XML file work fine. Once the watcher is started, I'm reading...
4
by: sadsan | last post by:
Hi everyone I'm after some advice and i don't know if this has already been developed or not. I'm wanting to be able to start a program automatically when its drop into a folder specifically a...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.