Andy Oakley

Program Manager, MSDN

Drag and drop file uploads in IE with .NET

I've received a couple of requests lately about how to implement drag-and-drop multiple file uploads in Internet Explorer from within managed code. Fortunately for me, someone else has already taken the liberty of writing an article on the subject at large: Host Secure, Lightweight Client-Side Controls in Microsoft Internet Explorer. Just a couple of tweaks and it'll be accepting files via drag and drop too.

In MultiUploadCtrl.cs, we need to enable drag and drop processing in the user control. Setting AllowDrop=True handles that in one swoop, now all that's left is the plumbing to handle the dropped files. For the events, DragEnter and DragDrop, the following should work well:

private void MultiUploadCtrl_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
 
if (e.Data.GetDataPresent("FileDrop"))
   
e.Effect = DragDropEffects.Copy;
 
else
   
e.Effect = DragDropEffects.None;
}

private void MultiUploadCtrl_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
 
new FileIOPermission(PermissionState.Unrestricted).Assert();
 
foreach (string fileListItem in (e.Data.GetData("FileDrop") as string[]))
 
{
   
if (!fileTable.Contains(fileListItem))
   
{
     
AddFile(fileListItem);
   
}
 
}
 
CodeAccessPermission.RevertAssert();
 
UpdateFileSizeDescription();
}

Published Monday, February 16, 2004 4:32 PM by aoakley
Filed under:
Anonymous comments are disabled

This Blog

Syndication

News

    The posts on this weblog are provided “AS IS” with no warranties, and confer no rights. The opinions expressed herein are my own personal opinions and do not represent my employer’s view in any way.

© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker