I'm having difficulty using NVelocity in an ASP.NET MVC application. I use it as a way to create letters.
As far as I can understand the details that I pass, everything is correct, but the template cannot be loaded.
Here is the code:
private const string defaultTemplatePath = "Views\\EmailTemplates\\";
...
velocityEngine = new VelocityEngine(); basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, defaultTemplatePath); ExtendedProperties properties = new ExtendedProperties(); properties.Add(RuntimeConstants.RESOURCE_LOADER, "file"); properties.Add(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, basePath); velocityEngine.Init(properties);
BasePath is the correct directory, I inserted this value into the explorer to make sure it is correct.
if (!velocityEngine.TemplateExists(name)) throw new InvalidOperationException(string.Format("Could not find a template named '{0}'", name)); Template result = velocityEngine.GetTemplate(name);
'name' above is a valid file name in a folder defined as basePath above. However, TemplateExists returns false. If I comment on this convention and let it fail when the GetTemplate method is called, then the stack trace will look like this:
at NVelocity.Runtime.Resource.ResourceManagerImpl.LoadResource(String resourceName, ResourceType resourceType, String encoding) at NVelocity.Runtime.Resource.ResourceManagerImpl.GetResource(String resourceName, ResourceType resourceType, String encoding) at NVelocity.Runtime.RuntimeInstance.GetTemplate(String name, String encoding) at NVelocity.Runtime.RuntimeInstance.GetTemplate(String name) at NVelocity.App.VelocityEngine.GetTemplate(String name) ...
I'm at a dead end right now. I feel the answer is blindingly obvious, but I just can't see it at the moment.