Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..i use drag and drop class to undergo process of data whenever a text file is drag into the form..But how to display a messagebox indicate wrong file format whenever file other than text file is drag into the form?Below are some codes of my program,did i wrong somewhere and where should i add?thanks.
C#
private void Form1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
        {
            string file= "";
            if(e.Data.GetDataPresent(DataFormats.Text))
            {
                file = (string)e.Data.GetData(DataFormats.Text);
            }
            else if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] fileNames;
                fileNames = (string[])e.Data.GetData(DataFormats.FileDrop);
                file = fileNames[0];
            }
Posted
Updated 29-Jul-12 22:35pm
v3

1 solution

C#
MessageBox.Show("wrong file format");



If a file is being dragged on, surely you can check the file extension and see if it's .txt ?
 
Share this answer
 
Comments
Esmond90 30-Jul-12 3:38am    
Thanks for reply..I mean how to let the programme know wrong format is dragged on?
Christian Graus 30-Jul-12 3:44am    
your drag argument must give you the file path, otherwise how could you open the file ? Or does it give a file stream ? If you have a file stream, try to read it and let the user know if you fail. Otherwise, do what I said before.
Esmond90 30-Jul-12 4:33am    
I have updated my question,is there any wrong and where should i add the Messagebox indicates the wrong format?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900