I want to loop through my javascript files. In the global.asax file on application start, I have this:
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.