.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> File Operation >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Check Particulare file Format are in the Folder using C#.Net

Posted By:Narayanan       Posted Date: February 26, 2012    Points: 40    Category: File Operation    URL: http://www.dotnetspark.com  

The following code returns Check Particular file format files in the Folder using C#.net
 

Declaration Part:
public static int chknofiles;
Function Part:
    public static bool chkfileextention(string filepath, string fileextension)
        {

            string[] fsDir = Directory.GetFiles(filepath);
            foreach (string f in fsDir)
            {
                string fName = f.Substring(filepath.Length + 1);
                string[] fileExt = fName.Split('.');
                if (fileExt[1] == fileextension)
                {
                    chknofiles = chknofiles + 1;
                }
            }
            if (chknofiles > 1)
            {
                chkfileextension = true;
            }
            else
            {
                chkfileextension = false;
            }
            return chkfileextension;
        }


Coding Part:
  bool chk = chkfileextention(txtBrowsFile.Text, "pcl");
            if (chk)
            {
                MessageBox.Show("true");

            }
            else
            {
                   MessageBox.Show("false");
            }

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend