Skip to content

Instantly share code, notes, and snippets.

@sachintha81
Created January 13, 2017 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sachintha81/e49bbc1d7dd0e68816225eaa23cb06eb to your computer and use it in GitHub Desktop.
Save sachintha81/e49bbc1d7dd0e68816225eaa23cb06eb to your computer and use it in GitHub Desktop.
C# - Drag Drop a File/Folder into a TextBox
using System;
using System.Collections.Generic;
using System.Windows;
using System.Collections.ObjectModel;
namespace TextBoxDragDrop
{
public partial class TextBoxDragDrop : Window
{
private void txtPath_PreviewDragOver(object sender, DragEventArgs e)
{
e.Handled = true;
}
private void txtPath_Drop(object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (files != null && files.Length != 0)
txtPath.Text = files[0];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment