Reputation: 44046
Is there, in silverlight, the ability to drag and drop files from the desktop into the browser? I seem to remember seeing something about it being a feature in silverlight 3.
Upvotes: 1
Views: 992
Reputation: 1712
You can Drag and drop from desktop in a silverlight 4 and above application. Check "Require Elevated permissions" in silverlight project properties and using drop event of silverlight datagrid one can handle the drag and drop from desktop in a silverlight datagrid.
private void DocumentsDrop(object sender, DragEventArgs e)
{
e.Handled = true;
var point = e.GetPosition(null);
var dataGridRow = ExtractDataGridRow(point);
if(dataGridRow !=null)
{.....
}
var droppedItems = e.Data.GetData(DataFormats.FileDrop) as FileInfo[];
if (droppedItems != null)
{
var droppedDocumentsList = new List<FileInfo>();
foreach (var droppedItem in droppedItems)
{
if ((droppedItem.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
{
var directory = new DirectoryInfo(droppedItem.FullName);
droppedDocumentsList.AddRange(directory.EnumerateFiles("*", SearchOption.AllDirectories));
}
else
{
droppedDocumentsList.Add(droppedItem);
}
}
if (droppedDocumentsList.Any())
{
ProcessFiles(droppedDocumentsList);
}
else
{
DisplayErrorMessage("The selected folder is empty.");
}
}
}
Set AllowDrop =true; in xaml for the datagrid. From the DragEventArgs extract the information as FileInfo Object. I am not sure about this working with Silverlight 3 application
Upvotes: 0
Reputation: 4945
I looked into this recently, and based on a post from a Silverlight MVP in the following thread, Silverlight 3 does not support file system drag and drop.
http://betaforums.silverlight.net/forums/t/117317.aspx?PageIndex=1
It appears Silverlight 4 now supports this:
http://www.silverlight.net/learn/videos/silverlight-4-beta-videos/silverlight-controls-drop-targets/
Upvotes: 3