Changing behaviour on missing files

37 views
Skip to first unread message

Alex Washtell

unread,
Apr 15, 2013, 7:07:17 AM4/15/13
to squi...@googlegroups.com
It seems by default that if you .Add() a file that is missing, a System.IO.FileNotFoundException when it tries to read the file. Is it possible to change this behaviour, either to another configurable option or by referencing our own custom code? 

I'm thinking that if possible it would just skip the file. Ideally if we could reference custom code then we could log the issue so it can get fixed. I can see why the default would be a catastrophic error, but for our purposes it would be better to handle it differently (i.e. a partially working front-end is preferable to a broken page).

- Alex

Alex Ullrich

unread,
Apr 16, 2013, 8:58:33 AM4/16/13
to squi...@googlegroups.com
This seems like a good use case for extension methods.  Something like this (untested)

public static BundleBase<T> AddCustom(this BundleBase<T> bundle, string filePath) {
if(File.Exists(Server.MapPath(filePath))) { 
bundle.Add(filePath);
 }
else {
//do some logging stuff
 return bundle; 

 

Alex Washtell

unread,
Apr 22, 2013, 2:43:30 AM4/22/13
to squi...@googlegroups.com
If there's nothing specifically to cater for it within SquishIt, that seems like a good approach, thanks.
Reply all
Reply to author
Forward
0 new messages