Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a file exist in the Server in ASP.NET

        string jSFile = ResolveUrl("~/MyProject/JavaScripts/dir/test.js");
        if (!System.IO.File.Exists(jSFile))
        {
           ...
        }

This code doesn't work and I guess it's the jSFile that doesn't work well with the IO.File.Exists but I know the jSFile has a valid path because when I use few line later

Page.ClientScript.RegisterClientScriptInclude("myfile",jSFile); 

it does attach the JavaScript file to the ASPX and all work fine.

Any idea of how to check if the file exist?

like image 829
Patrick Desjardins Avatar asked Feb 15 '10 19:02

Patrick Desjardins


1 Answers

if (!System.IO.File.Exists(Server.MapPath(jSFile)))
like image 186
Sky Sanders Avatar answered Oct 08 '22 21:10

Sky Sanders