473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 3223
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.