最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Check if a file exist in the Server in ASP.NET - Stack Overflow

programmeradmin0浏览0评论
        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?

        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?

Share Improve this question asked Feb 15, 2010 at 19:34 Patrick DesjardinsPatrick Desjardins 141k89 gold badges295 silver badges346 bronze badges 1
  • You should have indicated that the code is inside a UserControl. – Sky Sanders Commented Feb 15, 2010 at 20:00
Add a comment  | 

1 Answer 1

Reset to default 17
if (!System.IO.File.Exists(Server.MapPath(jSFile)))
发布评论

评论列表(0)

  1. 暂无评论