Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6834765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:09:07+00:00 2026-05-26T23:09:07+00:00

I’m sending an email from my ASP.NET MVC app using the Spark View Engine

  • 0

I’m sending an email from my ASP.NET MVC app using the Spark View Engine based on this example by Andrew Kharlamov.

I’ve setup a unit test, CanSendEmail, but I need to specify the viewfolder in the config.
I found the documentation here and the examples give this:

<spark>
  <views>
    <add name="{any-unique-name}" 
        folderType="FileSystem|EmbeddedResource|VirtualPathProvider|Custom"
        type="{name, assembly of IViewFolder type}"
        constuctor-param-names="values"
        subfolder="{optional subfolder to target}"/>
  </views>
</spark>

My question is this. Which folderType do I use and do I need any other parameters. My test product is call myProject.Tests and my web project containing the views is called myProject.Web with a Views folder in it.

Do I use FileSystem, VirtualPathProvider … ?

Edit [14/11/2011]:

Okay I’ve got this in my app.config in myProject.Tests:

<views>
    <add name="web-view-folder"
                folderType="VirtualPathProvider"
                virtualBaseDir="~/Views"/>
</views>

I still get “View source file not found.” when I run my test. I want the test to use the Views in myproject.Web.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:09:08+00:00Added an answer on May 26, 2026 at 11:09 pm

    My Solution

    Based on the blog posts here and here, and with help from @RobertTheGrey and looking at the tests in the Spark source code, I ended up using ViewFolderType.FileSystem. That worked.

    Here’s the my code under test:

    public string RenderEmailWithCustomViewFolder(string sparkViewName, ViewDataDictionary viewData, Dictionary<string, string> viewFolderParameters)
    {
        var settings = new SparkSettings()
            .SetPageBaseType(typeof (SparkView))
            .AddViewFolder(ViewFolderType.FileSystem, viewFolderParameters)
            .AddAssembly("MvcContrib");
    
        var engine = new SparkViewEngine(settings);
    
    
        var sparkViewDescriptor = new SparkViewDescriptor().AddTemplate(sparkViewName);
        var view = (SparkView)engine.CreateInstance(sparkViewDescriptor);
        try
        {
            // Merge view data
            viewData.Keys.ToList().ForEach(x => view.ViewData[x] = viewData[x]);
    
            // Render the view to a text writer
            var writer = new StringWriter();
            view.RenderView(writer);
            return writer.ToString();
        }
        finally
        {
            engine.ReleaseInstance(view);
        }
    }
    

    And here’s my test:

    [Test]
    public void Can_Render_Order_Confirmation_Email_With_Spark_View_Engine()
    {
        // Arrange
        var order = OrderInstanceFactory.CreateTestOrder();
        order.ContactEmail = "test@testicle.com";
        var emailService = new EmailService();
        var viewData = new ViewDataDictionary();
        viewData["Order"] = order;
        const string viewFolder = @"../../../../app/myProject.Web/Views";
        var viewFolderParameters = new Dictionary<string, string> {{"basePath", viewFolder}};
    
        // Act
        var emailBody = emailService.RenderEmailWithCustomViewFolder("Email/OrderConfirmation.spark", viewData, viewFolderParameters);
    
        // Assert
        Assert.IsNotNull(emailBody);
        Assert.IsTrue(emailBody.Contains("test@testicle.com"));
    }
    

    My OrderConfirmation.spark template lives in my web products in the Views/Email/.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Does anyone know how can I replace this 2 symbol below from the string
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.