[英]asp.net looping through javascript files
I want to loop through my javascript files. 我想遍历我的javascript文件。 In the global.asax file on application start, I have this: 在应用程序启动时的global.asax文件中,我有以下内容:
void Application_Start(object sender, EventArgs e)
{
//bugs this line
System.IO.DirectoryInfo info = new System.IO.DirectoryInfo("\\Scripts");
StringBuilder sb = new StringBuilder();
foreach (var item in info.GetFiles("*.js"))
{
sb.Append(System.IO.File.ReadAllText(item.FullName));
sb.Append(Environment.NewLine);
}
}
However, it's not working, it says it can't find files. 但是,它不起作用,它说找不到文件。 How do I programmatically get to a directory and its files? 如何以编程方式访问目录及其文件?
Thanks for your suggestions. 感谢您的建议。
Your path is almost certainly not correct. 您的路径几乎可以肯定是不正确的。
Use 采用
string mappedPath = HttpContext.Current.Server.MapPath("~\\Scripts");
System.IO.DirectoryInfo info = new System.IO.DirectoryInfo(mappedPath);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.