Search code examples
c#asp.netpdffile-exists

How to check if any pdf file exists on server?


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.