string jSFile = ResolveUrl("~/MyProject/JavaScripts/dir/test.js");
if (!System.IO.File.Exists(jSFile))
{
...
}
这段代码不起作用,我猜是 jSFile 不能很好地与 IO.File.Exists 一起工作,但我知道 jSFile 有一个有效路径,因为当我使用几行时稍后
Page.ClientScript.RegisterClientScriptInclude("myfile",jSFile);
它确实将 JavaScript 文件附加到 ASPX 并且一切正常。
知道如何检查文件是否存在吗?
最佳答案
if (!System.IO.File.Exists(Server.MapPath(jSFile)))
关于asp.net - 在 ASP.NET 中检查服务器中是否存在文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2268420/