Drag Drop to the Desktop after creation of the file? (C#) - c#

I have a query about drag-drop in C# using .NET.
My issue is with remote files. I have a list of remote files which the user can drag into an explorer window (desktop, etc). When such a drag occurs I want to be able to download the file and write it to the drop location.
The normal method of dragging files:
private void StartDragDrop(string FileToDrag)
{
MyControl.DoDragDrop(new DataObject(DataFormats.FileDrop, FileToDrag), DragDropEffects.Copy);
}
...does not suit my needs as I will not have the file data to populate the drag-drop object until after the DROP.
I have seen this functionality in many FTP clients and such.
Thanks in advance wizards.

It appears there is no logically straight forward method to do such a thing.
But there is a work around (with a substantial amount of work for such basic functionaliy) that can be found at codeproject.
If anyone finds a tidy way of doing it, let me know, I'd be intrigued.

Related

Folder explorer options

I have recently been assigned a task which sounded relatively simple!
Upon attempting it became clear it wasn't as straight forward as i first imagined!!!
I am trying to download multiple files to one location on the users machine. They select these files from lists within a custom share-point web part. Thats the bit i have managed to get working! The downloading is done via WebClient (System.Net.WebClient)
I now want to allow the user to select a location on their local machine to download the files to.
I thought i would be able to use but after attempting this i realized i can only pick files :( in order to get the desired location which will confuse the user
I want something similar to the above but i only need it to return a path location like c:\Temp or any other location the user prefers on their local machine.
Could anyone suggest a control that could provide this functionality. It can also be a share-point control.
In the meantime I will be attempting Tree view as i have never used these before and these may have the power to do this from what i have read
Cheers
Truez
Clarity on language ASP.NET
Unfortunately, you can't do this without some kind of active content, like a Flash control or spit activeX /spit.
It seems strange at first, but you have to consider that this kind of functionality would let a site discover the structure of anyones storage devices; this is not 'a good thing'™
However, perhaps a different approach might solve the problem?
Why are you using WebClient, can't you provide the link to the client and let them choose their own download folder ?
I ended up zipping the files in to one folder and passed the file to be downloaded through the browser! Thanks for your comments!

How to Save Controls that are inside a form

Hi this question or problem i have its very hard i have search and ask in the university and i have no idea how to make this happen, or even if it is possible.
Here we go...
I am making a photo or image editor with the variation of letting the user to insert buttons in top of the edited image(this buttons when clicked plays an audio file) all of this works so far.
BUT at the end when the user finish his work i need him to save it, so it can be send and view by others.
Now I think I know how to save an edited image but that dose not contain the buttons (controls) .... its like when we save a file at power point and we send it to others they contain audio and the image. Hope fully you guys understand if so can any one point me in a direction to do this or show me how if possible.
( Some people told me to use meta-data others the manifest file but I am so confuse).
too bad i cant post pictures of the work until i get 10 points......
Thanks For the first four quick response and sorry mistake of not telling that I am working on C# 3.5 .Net and in Windows Form app.
It seems you all quite understand what i am trying to do here. I will post the picture thanks to the points i receive from TheVillageIdiot. and about the XML I have never ever used that before ill try my best to understand you guys but if any one can show me an example two or were to read ( dose xml works on Windows form app.?) Here is ...( sorry if the picture its too big) an example of what the program it's doing so far that black transparent box its the MouseOverBackColor... when clicked it loads a player that plays x_x the sound. Its like tagging but with audio.
I really need help i reached my limit don't know were to look and the time is killing me.
HI I am back again this time with a simple sample of what i need to learn how to save the dinamic buttonarray
Today is 10/11/10 (i made a acount with !##$%share to share the sample with you guys i hope this dosent bother any one here) here is the Link . i will explain again what i need to do and i have no idea or code on how to do it.Imagine a person that uses the program and create like 5 buttons any were in the form , it needs to be save so he can send it to others that have the same program, this way others can view the buttons the user created.
hopefully you guys can help me out with a simple example i really neeed some sample working code. Note: I am working on windows form app WFA C# 3.5 .net M.V.studio2010 (the file I gave above has a backup with a 2008 vercion) thanx in advance.
Similar to jim's answer, I would suggest having an archive of some sort (ZIP or otherwise) containing all the media necessary.
Store the images and sounds files by name or checksum in the archive and keep the meta-data (button positions, names, what media they use, etc, we'll call it the definition file) in a file also stored in the archive. You may be able to use XML to make that human-readable.
The entire package will then be simple to distribute and use, as everything will be contained in the archive. Your application simply needs to scan for archives, check each archive for a valid definition file, and load the ones that are needed.
Edit: Going from the screenshot you posted and my understanding of the problem, I'm going to suggest the following:
When a user creates a button (defined as a rectangular area or "hotspot"), open a dialogue asking for a sound file to associate. Then, store the top-left and bottom-right corners of the button and the filename in a XML file, something like this:
<Button name="myButton!">
<Position top="128" left="128" />
<Size height="200" width="200" />
<Audio filename="something.mp3" />
</Button>
Now, when compiling a plugin, create a ZIP archive. Inside, place the XML file and all the audio files you need.
When loading a plugin, read the XML file first and find the audio file (assume all audio files are in the same archive as the XML file). Then create the button and add the audio filename as, say, its Tag property. Assign all buttons one generic OnClick event, and in the OnClick event, play the audio file given by the current object's Tag.
If you don't understand what I mean, I'll try to elaborate further. I think that method should work neatly and be pretty simple to work with. :)
One solution: Create a ZIP file that contains both audio and images.
Basically, you've got two things you want to save.
The edited image, and then the locations of the buttons and their actions.
You've got the image-saving part happening, so now you need to save the other information. This can be considered "metadata", and you can save it in some format that you invent, such that it allows you to load it back. Typically it would be easiest to do this via XML Serialization. So look into that.
Assuming you are writing a stand-alone application and no web - application.
If you are adding the Button as a .NET component (new Button()) there is no way to do that unless you supply your own player software with it.
If you want to supply your own player, create a (seperate) file with the info about the button and read the file and then re-create the button.
(Be aware though that all the resources - jpeg, mp3) also have to be available at the target PC) Alternatively, pack all you info into one file (jpeg, button infos, mp3's) and save that file.
hth
Mario
You have two choices
Create your own format and then make a player app that read it and play the results
Find some format that supports your features and create that kind of file. This works well if you expect others to have a player.
For #2, here are some formats that could support what you want to do
Flash
PDF
Compiled HTML Arhive -- need IE to play http://en.wikipedia.org/wiki/MHTML
EXE -- create code with resources and compile it -- basically your player + resources
PowerPoint

How to drop a file from windows form(listView) to desktop(any explorer window) without temp file

I know this is normaly implemented with a temp file but this wont work here since we are dealing with pretty large files stored in a database.
so far my idea is to create a small temp file that has a unique name and do a FileSystemWatcher monitoring the drop to get the path. but this doesnt seem optimal eighter.
are there any other ideas you guys could point me to?
maybe with virtual files? if so - how?
will be greatful for any hint.
thanks.
What you're looking for is a fully functional implementation of IDataObject. See http://www.codeproject.com/KB/dotnet/DataObjectEx.aspx for an example of how this can be achieved. This implementation allows you to provide a MemoryStream which contains the actual file drag/drop contents.

C# Drag and Drop functionality

I'm trying to achieve functionality similar to winzip/winrar, etc. I have a Treeview that displays the contents of a package (System.IO.Packaging). I want to be able to drag and drop a file or folder from the TreeView onto an explorer window or the desktop, etc. My problem is that I have to call DoDragDrop before I know if the object was actually even dropped. That means to create the DataObject with the FileDrop type, I must extract those contents of the package out to a temporary area and then provide that path to the DataObject before calling DoDragDrop. If the user doesn't drop on a capable container or cancels the drop, the overhead of extracting those contents is wasted. I've noticed that winzip does not actually create the temporary file until the drop occurs on a valid target. I've checked the DataFormats provided by the WinZip drop and they are normal FileDrop, FileNameW, FileName and Shell IDList Array. The first three simply hold a string to the temporary location that winzip extracted that file to. I'm not sure what the last one does.
Long story short, I want to be able to avoid extracting the contents until I know the drop location was valid. Is there a callback to figure out the drop location? Any suggestions would be extremely helpful.
System.Windows.DragDropEffects de = DragDrop.DoDragDrop(treeview1, dataObj, System.Windows.DragDropEffects.Move);
I've tried this with an application similar to an FTP server - I wanted to start downloading only after the user actually dropped the item. Unfortunately I found no way to do this using managed code only.
The way WinZip probably does it is by receiving COM callbacks (please forgive me if I'm using the wrong words here) and you'd have to create a managed wrapper around the native COM object in order to receive such callbacks yourself.
It's certainly possible, but I gave up and embedded a FolderTreeView thingie in my application to catch the drop events myself :/

Drag and drop to Desktop / Explorer

Following my scenario.
I got an Application which loads a Filestructure (Folders, Files) from a Database into a WPF ListView. Now I'd like to grab a file from this ListView, drag it over my Desktop (or some open explorer window) and drop it there. Basic Drag and Drop, nothing fancy. This sounds like a "standard" function for a windows application - but google won't help.
So how can I achieve this? Interops?
Thanks
Edit: Thanks for the solution, I still had to do some googling. Here's my complete solution.
DragDrop.DoDragDrop can do this as long as you pass it an appropriate DataObject.
First copy the files somewhere. You can use System.IO.Path.GetTempPath() if you don't have anywhere better.
Next create a string array containing the full paths to the files and do the following:
string[] paths = ...;
DragDrop.DoDragDrop(this, new DataObject(DataFormats.FileDrop, paths),
DragDropEffects.Copy);
It is actually possible to do this without pre-copying the files but that gets into some complicated IDataObject interactions, so unless your files are potentially very large and aren't already in the filesystem I would try this method first.

Categories

Resources