Excel file exist or not

Last Reply 6 days ago By PrinceG

Posted 7 days ago

Excel file exist or not in folderusing Web API?

You are viewing reply posted by: PrinceG 6 days ago.
Posted 6 days ago Modified on 5 days ago

Hi SUJAYS,

Use DirectoryInfo class.

Please refer below code.

Code

public void CheckFileExist()
{
    string folderPath = Server.MapPath("~/Files");
    DirectoryInfo directoryInfo = new DirectoryInfo(folderPath);
    FileInfo[] excels = directoryInfo.GetFiles("*.xlsx");
    string isExists= excels.Length > 0 ? "File exists." : "File does not exist.";
}

Output

File exists.