var server = HttpContext.Current.Server; var jsFiles = System.IO.Directory.GetFiles(server.MapPath("~/Scripts/jsPlugs"),"*.js", SearchOption.AllDirectories); var applicationPath = server.MapPath(null); foreach (var file in jsFiles) { var url = file.Replace(applicationPath, "~").Replace("\\", "/"); bundles.Add(new ScriptBundle(url.Replace(".js", "")).Include ( url )); }