Check if a file exists on the server Check if a file exists on the server asp.net asp.net

Check if a file exists on the server


the file path should be physical not virtual. Use

if (File.Exists(Server.MapPath(wordDocName)))


File.Exists() and probably everything else you want to do with the file will need a real Path.

Your wordDocName is a relative URL.

Simply use

string fileName = Server.MapPath(wordDocName);


Use

Server.MapPath("~/specifications/" + Convert.ToInt32(ViewState["projectSelected"]) + ".doc")

to get the fully-qualified path. That should do the trick for ya.