0

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.

1 Answer 1

3

Your path is almost certainly not correct.

Use

string mappedPath = HttpContext.Current.Server.MapPath("~\\Scripts");
System.IO.DirectoryInfo info = new System.IO.DirectoryInfo(mappedPath);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.