SIGN UP MEMBER LOGIN:    
ARTICLE

Drag and Drop Files in Silverlight 4

Posted by Diptimaya Patra Articles | Silverlight with C# May 13, 2010
In Silverlight 4, the plugin itself supports Drag and Drop events. In this article we will see how can we use the DropTarget to capture files from local system.
Reader Level:
Download Files:
 

Introduction

In Silverlight 4, the plugin itself supports Drag and Drop events. In this article we will see how can we use the DropTarget to capture files from local system.

Creating Silverlight Project

Fire up Visual Studio 2010 and create a new Silverlight Application Project. Name it as DragAndDropSample.

1.gif
 
Let's have a ListBox and a Border which can fulfill our requirement.

2.gif
 
As you see in above image, the RightSide pane is the Drop Target and the LeftPane will Populate the list of items dropped.

Let's have a class that will help us binding the files into listbox.

3.gif
 
Now let's change the default ItemTemplate of the ListBox.

4.gif
 
Now Let's have the Drop event of the Border so that we can capture the files.

5.gif
 
Now that everything is done in XAML, let's go to the code behind and write code into the DropHere event.
 
 6.gif
7.gif

8.gif
 
 
Now we are good to go. Let's have some files from the local file system and drop onto the Drop Area.

9.gif

10.gif
 
That's it.

Hope this article helps.

Login to add your contents and source code to this article
share this article :
post comment
 

Hi Patra, I need to implement the functionality of file upload to server with drag and drop. Please help me in implement this, also provide a sample example if you have. Thanks

Posted by Mohan Singh Feb 20, 2012

I have only one more thing to ask for. It would be nice if you could add to this tutorial the file data... for example as a binary data.

Posted by Thomas Foo Sep 14, 2011

hi i am new in silverlight how can get the full path of a file using drag drop i used, Path.GetFullPath(file.Name) but showing an error.. "File operation not permitted. Access to path 'Doc1.docx' is denied."

Posted by prince v Jun 12, 2011

very good step by step tutorials good work patra

Posted by Vijai Maurya Dec 16, 2010
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor