I am using Drag & Drop ListView on files (directories or any kind of files). When i drag&drop My Computer or Bin from Desktop NullReferenceException happens.
All i want is to skip this element (display some text in log textbox or smthing). I have no idea how to achieve that. I don't know what kind of object is MyComputer element from Desktop.
Here's my code after cutting useless to this subject logic:
private void Directories_ListView_DragDrop(object sender, DragEventArgs e)
{
string[] DroppedDirectories = (string[]) e.Data.GetData(DataFormats.FileDrop,false); //array of dd files paths
try
{
foreach (var directory in DroppedDirectories) // here Exception occurs this loop process all dragged and drop files
{
ListViewItem Dir = new ListViewItem(Path.GetFileNameWithoutExtension(directory));
//Place for some checking Logic
if (GetDir.IsDirectory(directory))
{
(.....);// Doing some things
}
else
LogList.Items.Add(DateTime.Now + ": Entry " + Dir.Text + " is not a directory");
}
}
catch(Exception) // it only stops app from crashing,
{
LogList.Items.Add(DateTime.Now + "One of elements was Mycomputer or Bin, process stopped ");
}
}