This project is read-only.


Nearforums is a forum application built on top of ASP.NET MVC framework. Nearforums natively stores data in SQL Server or MySQL. Nearforums extension for XML data access allows the Nearforums application to store data in XML files.

The code for Nearforums extension for XML data access can be found in The uploaded file has the complete source. The original nearforums source code can be found in The following steps can help you set Nearforums for XML data storage:
  1. Download the Nearforums application
  2. Download the Nearforums XML extension
  3. Update the source files in Nearforums application
  4. Append XML files in the Nearforums application

Download the Nearforums application

The Nearforums application can be downloaded from The application contains the following projects:
  • NearForums
  • NearForums.DataAccess
  • NearForums.Services
  • NearForums.Tests
  • NearForums.Web
  • NearForums.Web.Controllers
  • NearForums.Web.Output
Build the solution and check if it works. The default solution works with a SQL server or MySQL database. Now, we will extend this solution to work with XML data.

Download the Nearforums XML extension

The Nearforums extension for XML data access can be downloaded from The unzipped file contains the following details:
  1. NearForums.DataAccess.Xml project
  2. Data folder (data)
  3. Referenced Library folder (lib)
  4. Source folder (src)
The NearForums.DataAccess.Xml project is the main project which has all the source files needed to store XML data. This project should be added to the NearForums solution (extracted in the step above).
The data folder (data), referenced library folder (lib), source folder (src) can be safely excluded from the solution.

Update the source files in the Nearforums solution

There are four files that needs to be modified in the original Nearforums solution:
  1. NearForums project
    1. Configuration/AppSettings.cs
    2. Configuration/SiteConfiguration.cs
  2. NearForums.Web.Output project
    1. Web.config
    2. DependenciesHelper.cs
Let us look at the changes one by one. In the SiteConfiguration.cs file, the AppSettings element is added:
        public AppSettingsElement AppSettings
                return (AppSettingsElement)this["appSettings"];
                this["appSettings"] = value;
The AppSettings.cs should be added to the NearForums project under the Configuration folder. This will ensure that the DataPath - path where the XML files are stored is available to the extension.
        private string _dataPath;
        public string DataPath
                if (_dataPath == null)
                    _dataPath = ConfigurationManager.AppSettings["DataPath"];
                return _dataPath;

                _dataPath = value;

Next, we have to do a few changes in NearForums.Web.Output project. The DependenciesHelper.cs uses AutoFac to resolve the interfaces. In our case, we want to make sure that the DataAccess interfaces resolves to the classes in the NearForums.DataAccess.Xml project.
				.Where(t => t.Name.EndsWith("DataAccess"))

After we have resolved the interfaces with the classes in our project, we have to make a few changes to the web.config as well. The NearForums Membership provider should use our XmlMembership provider rather than the inbuild SqlMembership provider. The following change in Web.config ensures that this change happens:
<add type="NearForums.DataAccess.Xml.XmlMembershipProvider" name="ForumsMembershipProvider" applicationname="NearForums" passwordattemptwindow="10" minrequirednonalphanumericcharacters="0" minrequiredpasswordlength="6" maxinvalidpasswordattempts="30" passwordformat="Hashed" requiresuniqueemail="true" requiresquestionandanswer="false" enablepasswordreset="true" enablepasswordretrieval="false">
AppSettings in Web.config should also have an additional settings element - DataPath as follows:
    <add key="XmlDataPath" value="" />

Append XML files in NearForums application

The XML files in the data folder should be moved to the App_Data folder in NearForums.Web.Output project. The following screenshot gives an idea of how the project should look:
Build the solution and test. The application should now save data in XML files.

Last edited Jan 21, 2013 at 10:49 AM by vijayst, version 7


No comments yet.