문제

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