views:

196

answers:

1
        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?

+5  A: 
if (!System.IO.File.Exists(Server.MapPath(jSFile)))
Sky Sanders
What is the namespace of Server.MapPath?
Daok
If you are inside of the web context, it should map automatically, otherwise you would use the full path.
Kyle B.
I only have base.MapPathSecure but it does work :) but why?
Daok
@Daok: Look at your inheritance tree.
Steven Sudit
HttpContext.Current.Server.MapPath();
Sky Sanders
I think this answer is good BUT more I read about MapPathSecure and more I think it's better to use it when possible before using MapPath. What you think?
Daok
I think now that you know the options you will make the right choice. ;)
Sky Sanders