0

I know that I can can add search locations to a View Engine as explained in this answer.

I was just wondering is there any way to tell the view engine to then recursively search sub folders without having to specify the entire path?

E.g. if I had a folder structure like /Shared/Partials/Subfolder/Subfolders/MyView

Could I add a search locations like /Shared/Partials/* or similar?

I can't find anything so I don't think it is possible but thought I may as well ask here.

Thanks

Community
  • 1
  • 1
davy
  • 4,474
  • 10
  • 48
  • 71

1 Answers1

1

What if you use something like this in your viewengine array?

Directory.GetDirectories("c:/somepath/Shared/Partials");

The above returns an array of strings.

So you could write the following:

public class CustomViewEngine : WebFormViewEngine
{
    public CustomViewEngine()
    {
        var viewLocations =  Directory.GetDirectories("c:/somepath/Shared/Partials");

        this.PartialViewLocationFormats = viewLocations;
        this.ViewLocationFormats = viewLocations;
    }
}

And also register your new engine:

protected void Application_Start()
{
    ViewEngines.Engines.Clear();
    ViewEngines.Engines.Add(new CustomViewEngine());
}
e4rthdog
  • 5,103
  • 4
  • 40
  • 89