Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


i written the code to check whether the image exist in a folder or not without using single extension,but i need to check the all images extensions how i can modify the script

i.e i want to check if for ,jpg,.jpeg,.png,.gif extension


var path = "../mapimages/" + name + ".png";
$.ajax({
url: path,
type: 'HEAD',
error: function () {

alert("does not exist");
},
success: function () {


alert("file exists do something here");
}
});
Posted
Updated 12-Jul-14 3:32am
v2

1 solution

In C# You can check programmatically by passing folder name and image name or just image name if folder is fixed

C#
string folderPath = "Images";
string fileName = "img1";
DirectoryInfo root = new DirectoryInfo(Server.MapPath("~/"+folderPath));
FileInfo[] listfiles = root.GetFiles(fileName+".*");
if (listfiles.Length > 0)
{

    //File exists
    //do some code
}
else
{
    //File does not exist
    //Do some code
}
 
Share this answer
 

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

  Print Answers RSS


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