Orchard CMS 1.5.1 – Filtering Content by Taxonomies

Filtering contents by Taxonomies or categories in Orchard can be a challenge. I’ve found articles talking about cycling through taxonomies in a specific Content Type, but not one to get a list of Content Items for a custom filter. The reason I couldn’t use other methods is that I’m creating a custom search based on several other criteria, including a text field entered by the user.

Taxonomy terms are of type System.Linq.Enumerable.WhereSelectEnumerableIterator<Contrib.Taxonomies.Models.TermContentItem,Contrib.Taxonomies.Models.TermPart> which is difficult to work with. So after some trial and error, I found a way to do this.

In this example, I have a Content Type named Product. Inside the Product Content Type, I have a Product Part which contains the Brand taxonomy.

The method below takes in a brand name, and returns a IEnumerable<dynamic&gt list of Product Content Type with the brand name specified by the argument

private readonly IOrchardServices _orchardServices;

private IEnumerable<dynamic> GetFilteredItemsByTaxonomy(string taxonomyTerm)
    // Filtering for only product Content Type 
    //   Using the dynamic type to access the taxonomy data directy
    IEnumerable<dynamic> products = _contentManager.Query(VersionOptions.Published
        , new string[] { "Product" }).List();

    // Filtering the products by brand where it contains the taxonomyTerm
    return products.Where(x => 
        .Select(y => y.Name).Contains(taxonomyTerm));

I would like to mention that PluralSight has a great Orchard Tutorial on Orchard modules.

XCode 4.2: Controlling the Detail View from the Master-Detail Template (iOS 5)

In XCode 4.2 (using the iOS 5 SDK), the Master-Detail Application template has replaced the old Split View Application template. Many of the components such as the RootViewController class and the MainWindow.xib no longer exist. The template is much simpler, but it does take some getting use to. The main problem is to control the DetailViewController from the MasterViewController. When running the template without modifications, the MasterViewController only controls itself, and has no control over the DetailViewController. This is a walkthrough of the process of gaining access to the detail side.

Getting Started with the Master-Detail Application Template

1. Start a new project then select the Master-Detail Application Template.


2. For this sample, set the Device Family to iPad and disable the “Use Storyboard”.


3. Run the app in your iPad simulator, and you’ll notice when you click the menu, it only affects itself, not changing the large detail view.


When looking at the code from MasterViewController.h, there is a pointer called detailViewController, this is not a reference to the large detail view in the split view. Instead, it is a reference to the new menu screen that will be pushed on to of the menu table.

Referencing the DetailViewController

At this point there is no way to change anything in the large DetailViewController. This is how you add that reference:

1. Add the following line to the MasterViewController.h file:

@property (strong, nonatomic) DetailViewController *mainDetailViewController;


2. Add the synthesize statement to your MasterViewController.m file:

@synthesize mainDetailViewController;


3. Add the reference to mainDetailViewController from AppDelegate.m:

masterViewController.mainDetailViewController = detailViewController;


4. Now you can start making changes to the large DetailViewController. Let’s change the wording in the label. In the didSelectRowAtIndexPath function in the MasterViewController.m, add the following line:

mainDetailViewController.detailDescriptionLabel.text = @"I did it!";


Now you can run the app, and you will notice that when you press the Detail cell, you will change the text in the main detail view.

Programmatically Attaching an Excel Document to an Email in .NET

Periodically clients will ask me to send them a report from a database. Instead of creating an Excel spreadsheet from the database and then attaching it to an email, I have automated the process. The following function will take in a MailMessage object by reference along with a DataGrid object and filename string. The function then attaches an Excel file containing the DataGrid contents to the MailMessage object.

This function uses the following inclusions: System.Net, System.IO, System.Net.Mail, System.Collections, System.Collections.Generic

    // Function attaches a DataGrid to Email in Excel Format
    private void AttachDataGridToEmail(ref MailMessage mailMessage, DataGrid dataGrid, String filename)
        MemoryStream ms = new MemoryStream();
        System.IO.StringWriter stringWriter = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
        byte[] excelFile = StrToByteArray(stringWriter.ToString());
        ms.Write(excelFile, 0, excelFile.Length);
        ms.Position = 0;
        Attachment attachment = new Attachment(ms, filename + ".xls", "application/vnd.xls");

MS SQL – “Create failed for User” Error During Database Restore

When migrating a database, from one location to another, you may encounter a problem with the users. The database backup/restore method does not transfer the users. When you try to create the user after the restore process, you will get:

Create failed for User dbusername. (Microsoft.SqlServer.Smo)

Additional information:

An exception occurred while executing a Transact-SQL statement or batch.

User, group, or role ‘dbusername‘ already exists in the current database. (Microsoft SQL server, Error: 15023)

This problem is caused by an internal id conflict of the users. It can be corrected by a few lines. For this example, let’s assume your restored database is named EmployeesDB and your user is employeeDBAdmin.

Click on New Query, and type the following.

Use EmployeeDB
sp_change_users_login 'update_one', 'employeeDBAdmin', 'employeeDBAdmin'

Click on ! Execute.

This will synch your users, and you will be able to log into the database as usual.

The full details of this solution can be seen at the Microsoft KB 274188.

Fixing the – warning: UUID mismatch detected with the loaded library

While developing in iOS, I will sometimes get an annoying error while loading apps in different iOS version. The UUID mismatch error looks like this:

UUID mismatch detected

Depending on which version of iOS you are working on, the sections in red and green (below) might differ from mine:

warning: UUID mismatch detected with the loaded library – on disk is:
/Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.3 (8J3)/Symbols/System/Library/Frameworks/CoreGraphics.framework/Resources/libCGFreetype.A.dylib

This problem can be fixed from your terminal. Simply add enter the line below matching the green and red sections from your warning message. You may be required to enter your password.

sudo rm -rf /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.3\ \(8J3\)/

After the command above, unplug your iOS device, restart XCode, and plug your device back in.

If the Organizer window does not open in XCode, go to Window -> Organizer in the top menu. Select the device on the left, and choose Collect Data from the main panel. XCode will gather all the information it needs, and you will be all set to develop on the device.

Thanks to Charles Schmidt from Off Hours Agency for help in discovering this solution.

Providing Alternate Content for Flash Objects with SWFObject

HTML 5 is supposed to take over the Internet sometime in the future, but the predictions are always changing. Until then, Adobe® Flash® remains the easiest way to create interactive animations online. Since Apple mobile devices using iOS, such as iPhone and iPad, are not compatible with Flash, it’s nice to have a detection mechanism to provide alternate content. SWFObject provides a simple and clean solution to your alternate content problem. SWFObject also allows you to add Flash content without all the messy javascript code generated by default during Flash publication.

You can view the example below in my SWFObject Sample Page. If you disable flash in your browser or device, the page will only display a static image. It’s a great way to gracefully degrade your website. You can also use this method to detect older versions of Flash. Believe it or not, some corporations will not allow employees to upgrade their Flash Player.

Here is a simple example of how to use SWFObject:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>SWFObject Sample</title>

	<!-- Including SWFObject from Google -->
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
	<script type="text/javascript">
		var params = {
				allowscriptaccess: "always",
				menu: "false"
			var flashvars = {};
			var attributes = {};
			if (swfobject.hasFlashPlayerVersion("9")) {
				// SWFObject will load "animation.swf" into tag with id of "containerWrapper"
				swfobject.embedSWF("http://www.zugno.com/coderscooler/samples/swfobject-sample/animation.swf", "containerWrapper", 300, 100, "9.0.0", false, flashvars, params, attributes);

	<div id="containerWrapper">
    	<!-- Contains the content to display if media does not display Flash, or Flash version is below 9.0.0 -->
    	<img src="http://www.zugno.com/coderscooler/samples/swfobject-sample/animation.gif" width="300" height="100" alt="Animation Image" />
    <p>Animation will show in Flash (version 9.0.0 or higher) enabled devices, otherwise it will show a static image.</p>

For the sake of simplicity, I just added an image to replace the flash, but in your site, you can include HTML in your alternate text. I have also used jQuery to animate the items and to provide interactivity for users without Flash.

WordPress in Dreamweaver CS5 with the IIS 7.5 Platform

PHP ImageWordPress and Adobe® Dreamweaver® CS5 (and CS5.5) can work together in your Internet Information Services (IIS) 7.5 platform. Although WordPress works best in the Apache environment, it does work with the Windows environment too. Dreamweaver can work with WordPress to help developers organize its fragmented PHP structure.

I hadn’t used Dreamweaver in a long time because there are plenty of other html editors out there that did a better job in my opinion. When I heard that Dreamweaver CS5 would support WordPress, Joomla!, and Drupal, it gave me a reason to come back. Not only does it help keep the fragments of the CMS together, but offers code-hinting, which helps developers stay sane.

I found a great tutorial series from Adobe called “Editing a WordPress theme with Dreamweaver CS5” that covers a lot of material, but it only shows the use of the XAMPP and MAMP environments. After some trial-and-error, I got it working on IIS 7.5.

Installing WordPress on your local machine

To get WordPress running on your local machine, you need to install PHP and MySQL™. You can install them manually, or use the Web Platform Installer in your IIS Manager to install it for you.

IIS Web Platform Installer 3.0 Icon Screenshot

For this example, I installed my local WordPress site at http://localhost:8888. Make sure your local website runs properly before proceeding.

Viewing WordPress in Dreamweaver

Now you need to apply the correct settings to run WordPress in Dreamweaver:

1. Open DreamWeaver, and go to Site -> Manage Sites
2. In the pop-up window, click New…

DreamWeaver Manage Sites


3. Select the Site sub-menu (on the left), enter a name for your site, and its local path

DreamWeaver Site Setup


4. Select the Servers sub-menu (on the left), and click on the + under the table

DreamWeaver Server Setup


5. In the Basic tab, select Local/Network from the drop-down in the Connect Using: row.

DreamWeaver Server Basic


6. In the Advanced tab, under the Server Model: row, select PHP MySQL

DreamWeaver Server Advanced


7. After the new server row appears, uncheck the Remote checkbox, and check the Testing checkbox

DreamWeaver Site Testing Checkbox


8. Under the Advanced Settings -> Local Info, ensure your local host is correct

DreamWeaver Local Info


9. Click the Save button to save your settings
10. On DreamWeaver’s top menu, go to Site -> Site-Specific Code Hints…
11. Select WordPress for the Structure


DreamWeaver can now recognize your locally stored WordPress. If you select index.php, you can see all the dependencies listed (circled in red). You can also take advantage of the Live View to see the PHP code executed.

DreamWeaver Live View


If you have completed the setup properly, you can test the code hinting by typing $wp_ inside the php tags. If you don’t see it, try ctrl + space to activate code hinting.

DreamWeaver Code Hinting in Action

Although this setup is a lot of work, I found it to be very useful in developing WordPress sites. If you have a complicated template, it may take you a long time to find the file responsible for the section you need to change. With DreamWeaver, it’s easy to find the php fragments, and CSS.

%d bloggers like this: