Reputation: 4562
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
Upvotes: 0
Views: 185
Reputation: 5233
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());
}
Upvotes: 1