I have a code like this:
string fileLocation = Request.Form["FileName"].ToString();
if (!string.IsNullOrEmpty(fileLocation))
{
var deleteFile = fileLocation.Split('\\')[1];
var pathe = Path.Combine(uploadPath, deleteFile;
if (System.IO.File.Exists(pathFile))
{
System.IO.File.Delete(pathFile);
}
}
Usually if i don't select a file, Request.Form["FileName"].ToString()
will return a SystemNullException which I intend to set it as null.
Is there anyway i can do it without using try catch?