I am working on a Windows Forms Application.
During one Drag and Drop action on a TextBox
control, I want to restrict the user to provide only a text file.
// drag drop module for input text file in textbox starts here
private void textBoxInputTextFile_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
private void textBoxInputTextFile_DragDrop(object sender, DragEventArgs e)
{
if(e.Data.GetData(DataFormats.FileDrop, true))
{
// Check if it is a text file
// Okay if it is a text file or else give an error message
}
}
This code is just a sample from my previous folder drop action but now I want to restrict it to only one file and that too must be a text file. So that, when the drop action happens, it should check first if it is a text file or not and then do other stuff.
How do I do that?