In a vb.net , how can I block a drag and drop operation , if these condition are true :
1) If the user drag a folder
2) If the user drag a file that is not an Excel file or Word file
3) If the user drag more than 1 file
Thank you !
In a vb.net , how can I block a drag and drop operation , if these condition are true :
1) If the user drag a folder
2) If the user drag a file that is not an Excel file or Word file
3) If the user drag more than 1 file
Thank you !
Alex,
Your trying to accomplish much in a routine that requires very little code. The Drag event is supposed to return very quickly so that the UI can continue rendering and the UI remains responsive. For you to burden it with complicated file checking stuff would hider its responsiveness and introduce a very bad situation.
In the case of your UI crashing, that is supposed to be handled by you via error handling. The fact that your UI becomes inoperative means your not handling the situation properly.
The best approach is to constrain the user via file extension, a single file, not a folder and file size (meaning file size is less than 4MB for example). Then your code should assume the file is valid. Then pass the file to Excel (or what every the next process is), and let that process throw an exception. Then handle that exception and present a meaningful error information to the user like: "The file is not a valid Excel spreadsheet.".
Please understand that we are trying to help you implement a best practice and not a preferred practice; which is most cases makes your product unusable or unstable.