Check file extension using LINQ

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under LINQ category on | Points: 40 | Views : 196
Write below code:-
string ext = System.IO.Path.GetExtension(file_name);
string[] validFileTypes = { "pdf", "gif", "jpg","jpeg", "bmp", "png", "Text", "img" };
bool isValidType = validFileTypes.Any(t => ext.ToUpper() == t.ToUpper());
if (isValidType)
{
Response.Write("Valid File");
}
else
{
Response.Write("Invalid File");
}

Comments or Responses

Login to post response