Yes you can find all the files with certain extension, here is a sample code:
string[] files = System.IO.Directory.GetFiles(Server.MapPath("/somepath"), "*.txt");
Hope this helps.
Question
Is it possible to check if any file with .pdf extension exists on server? I know i can use: File.Exists(Server.MapPath("/somepath"))); but this is when I'm looking for specific file. Is it possible to just look for the file extension?
Solution
Yes you can find all the files with certain extension, here is a sample code:
string[] files = System.IO.Directory.GetFiles(Server.MapPath("/somepath"), "*.txt");
Hope this helps.
OTHER TIPS
Currently i'm working with this Method:
public IEnumerable<FileInfo> FindFilesInDirectory(string dirPath)
{
return Directory.Exists(dirPath)
? Directory.GetFiles(dirPath, "*.pdf", SearchOption.AllDirectories)
.ToList()
.ConvertAll(x => new FileInfo(x))
: null;
}
Not sure if it works with Server.MapPath("/somepath")