简体   繁体   中英

Combining directory files in asp.net with custom-built process

I have two directories that contain files. I want to combine all these files into one. I already know about native minification but I don't want to do that because I need something custom-built (it's a single-page app and there are several conditions on which files to include into which output based on the type of users and a few other conditions).

Let's say that in folder MyScripts I have files Script1.js, Script2.js .... Script14.js . I want to use a string builder to open and append these files and then create a consolidated MyFullScript.js file that's saved into the MyScripts folder. I'm not sure where to look for this, what are some ways of doing this?

Thanks.

Why not write a quick function on c# to concatenate everything as so:

DirectoryInfo  info = new DirectoryInfo ("c:\\temp"); //Path to JS files
StringBuilder sb = new StringBuilder();

foreach(var item in info.GetFiles("*.js"))
{
    sb.Append(File.ReadAllText(item.FullName));
    sb.Append(Environment.NewLine);
}

Now sb has all your scripts concatenated; you can save the string to a new .js file if that's what you need.

Hi this may or may not help, came across it when implementing jQuery FileUpload by blu-imp. Anyway provides bundling and minification services as required, seemed quite configurable to me, more so than the native stack anyhow and may provide the granularity you need!

http://clientdependency.codeplex.com/

After re-reading your post I think this may well be of help, especially as the source code is available on code-plex so I figure this may provide 80% of the functionality you need whereby you may have to fork it and add a custom 20% to get it to how you need it!

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM