2012-02-23 33 views
1

在FileZilla中,我可以在遠程站點上選擇一個文件並將其拖到我的桌面上。 我將文件放在桌面上,FileZilla開始流式傳輸文件。如何將遠程項目從WPF拖到桌面上?

我想實現類似的功能使用WPF - 這是可能的,它是如何做到的?

下面的代碼展示瞭如何使用文件路徑將本地文件拖動到桌面上。我的場景不同之處在於,在調用DragDrop.DoDragDrop時,文件不具有物理可用性。

//FileDetails holds information about where the file is downloaded from. 
FileDetails fileDetails = (FileDetails)listView.ItemContainerGenerator. 
    ItemFromContainer(listViewItem); 

DataObject dragData = new DataObject(DataFormats.FileDrop, fileDetails); 
DragDrop.DoDragDrop(listViewItem, dragData, DragDropEffects.Copy); 
//At this point control goes to the OS. 

理想情況下,我希望檢測'drop'事件以及有關放置位置的信息。另一種選擇可能是將StreamWriter傳遞給DoDragDrop(),並在接收到字節時將其寫入它。

+0

你想實現類似的東西:http://stackoverflow.com/questions/3040415/drag-and-drop-to-desktop-explorer? – Guillaume 2012-02-23 09:08:17

+1

@Guillaume--回答關於如何拖放已存在的文件的問題,但除非我錯了,否則我不認爲它涵蓋了在文件被刪除後流式處理文件這一更棘手的問題。 – 2012-02-23 10:22:56

+0

@ bobsmith833確實,你是對的...... – Guillaume 2012-02-23 11:07:22

回答