In WPF I have a textBox . I need to drag and drop textfiles ie in notepad from desk top to textbox of wpf. I managed to get the contents of notepad to textbox. But I need file path to be in browser so that I can transfer files from client to client. help please.
The code below helps me to display content of notepad in textbox. I need the file path instead.
privatevoid textBox1_PreviewDragEnter(object sender, DragEventArgs
e)
{
bool isCorrect = true
;
if (e.Data.GetDataPresent(DataFormats.FileDrop, true) == true
)
{
string[] filenames = (string[])e.Data.GetData(DataFormats.FileDrop, true
);
foreach (string filename in
filenames)
{
if (File.Exists(filename) == false
)
{
isCorrect =
false
;
break
;
}
FileInfo info = newFileInfo
(filename);
if (info.Extension != ".txt"
)
{
isCorrect =
false
;
break
;
}
}
}
if (isCorrect == true
)
e.Effects =
DragDropEffects
.All;
else
e.Effects =
DragDropEffects
.None;
e.Handled =
true
;
}
privatevoid textBox1_PreviewDrop(object sender, DragEventArgs
e)
{
string[] filenames = (string[])e.Data.GetData(DataFormats.FileDrop, true
);
foreach (string filename in
filenames)
textBox1.Text +=
File
.ReadAllText(filename);
e.Handled =
true
;
}