Search  Search  

Drag and drop a file in C# - easy.
  More Programming ... on Twitter on YouTube on flickr on Pinterest on Facebook on Google+ on Tumblr on LinkedIn

Free wallpapers of the hottest girls of the 2014 Winter Olympics

Complete guide for Euro 2012’, about 300 hundred pages filled with comprehensive information about Euro 2012

Euro 12 - teams, managers, players, fixtures, referees, the brand new ‘Tango 12’ Adidas ball and much, much more. Few hundreds amazing photos.

E-books, free e-books, Euro 2012 e-books

Auckland events in photos at

1 500 photos of fun-run 'Ports of Auckland Round the Bays 2012' at

Ocean swim - more than 1 500 photos of State King of the Bays Forums forums Forums - articles, news, links Forums - articles, news, links 

Photos of State King of the Bays event at

‘Complete guide for Euro 2012’: Given profile all 368 footballers with their photos.

‘Complete guide for Euro 2012’: Read about star players of each squad. Find out who is the key player of each team. What Pele expects of Euro 2012?

‘Complete guide for Euro 2012’: Compare annual salary of coaches participating in the Euro-2012 - and how it happened that the team of the most paid coach finished the last in their group?

‘Complete guide for Euro 2012’: Euro 2012 footballers: who are the most expensive players? Who are the Rising stars at Euro 2012?

E-books, free e-books, Euro 2012 e-books
 Rating: 3.4      Rate this article   35 
 07 Aug 2011

Drag and drop a file in C# - easy.



To work with files in Visual Studio there are several controls, OpenFile Dialog, etc. But it may be a bit slow moving through file system to desired folder and file. And in case if you have already open necessary folder, you can drag and drop file to your application within one second.

To implement such a feature, you will need to change just one setting and write few lines of code.

Usually text boxes are served for such purposes. So in Text Box property AllowDrop change it to True (default setting is False). After that, add two events to your text box:

DragEnter event and DragDrop event. The code should be as follows:


private void txtThumbFile_DragEnter(object sender, DragEventArgs e)
    // Make sure that user actually dropping files (not text or anything else)
    if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)
        // Allow to continue, otherwise without this, the cursor shows a "NO" symbol
        e.Effect = DragDropEffects.All;


private void txtThumbFile_DragDrop(object sender, DragEventArgs e)


    string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

    this.txtThumbFile.Text = files[0];



And now you have full path to the file in your text box. So you can open file, attach to email message, etc. depending of your program.



Move file to the text box.

Cursor changed, showing that control (Text Box) can accept the data.

Drop the file, it shows the full path to the file.

  More similar links:

How to open documents in Microsoft Visual Studio 2010 on the right of existing Tab.

How to copy folder with its permissions?

Unsafe Code in C#

How to fix HTTP Error 404.3 - Not Found (aspx file not recognized by IIS)

Unsafe Code Usage in C#

How to fix error ‘A potentially dangerous Request.Form…’ – even when ‘ValidateRequest’ set to false.

How to test string for a number?

 Rate this article from 1 to 5 


15.04.2012    Vera

A smpile and intelligent point, well made. Thanks!

        Add comment
Your name:
Your comment:
 Tags: C#, Code, SoftFern Tutorials, SoftFern free Tutorials and Article, SoftFern Windows and other Operatin, SoftFern Programming Tutorials, Drag and drop a file, OpenFile Dialog, drag and drop, DragEnter, DragDrop, event, file, text box
   More Programming ...

  Home page Weird We sell Programming Windows
  News Our Photos Photoshop and Photography SQL server Microsoft Office
  Tech News Our Portfolio iPad Misc Web sites development
  Videos Archive Androids Graphic design Software development
  Auckland and New Zealand About Us Tablet PCs CD/DVD presentation Play games online
  Football Contact us Round the Bays 2012 photos Ocean Swim 2012 photos Auckland Events
  Sport Our Portfolio Stock Images Stock Photos Links Exchange
  Hot Girls Our clients On Twitter Add link Site Map
  Our Twitters’ gadget Site Map Google+ Site Grid
  Health and Beauty Site Grid Pinterest Natalia Soft Fern forums
  Misc News Web pages Facebook Photos, images Hair & Beauty
  On YouTube CD/DVD presentaton Tumblr Daily Motion Flickr
  YouTube - 2 Graphics LinkedIn Live Journal Stumble Upon
  Vimeo - videos Tutorials - Videos Tutorials - Weird Most Popular on Internet Yahts, boats, Tall Ships

SoftFern (New Zealand LTD). 
Design and development by SoftFern 2003 - 2014 Graphics supplied by