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?

有帮助吗?

解决方案

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.

其他提示

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")

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top