Saturday, January 21, 2012

Get File Extension From File Name that Saved into the Folder in Application.


{
            string s=Server.MapPath("~/Images/");
            DirectoryInfo di = new DirectoryInfo(Server.MapPath("~/Images/"));
            FileInfo[] smFiles = di.GetFiles();

            foreach (FileInfo fi in smFiles)
            {
                if (Path.GetFileNameWithoutExtension(fi.Name) == "DefensiveDrivingLargeVehicles_img01")
                {
                   lblExtension.Text = Path.GetFileNameWithoutExtension(fi.Name) + fi.Extension;
                   break;
                  
                }
           }
}
Here There are some Files in Images Folder.Now If i Want to Get Extension of an Image DefensiveDrivingLargeVehicles_img01 .then above code is useful to get the FileExtension.here I am going to print the FileName+FileExtension in Lable...

0 comments:

Post a Comment