RTE News Reader hits the Windows Marketplace

RTE News Reader App for Windows Phone

Over Christmas I decided to dip my toes into making a Windows Phone app for my Lumia 800. If there's one app that I was missing when I moved over to Windows Phone from iOS it was the RTE app. There was no official app so I went about making a quick little app to pull in their RSS feed and make readings the news stories a bit easier to consume on the phone.

I ran into issues straight away as the RTE feed does not support RSS 2.0 which a lot of the code samples out there seem to be using. Thankfully as I've been using Linq to XML so much in my job I did a little workaround to allow me take in the feed in the app. After that any other issues I had were just your basic 'getting to grips' issues. Funny things like finding out that Windows Phones can't support GIF images out of the box or that they only have 16bit displays so gradients look crappy caught me off guard as I coded up the app.

Thankfully I could work around these limitations. Making the app was a great learning experience and was actually surprisingly easy to do for a typical .net developer. If I have one complaint it would be that the App Hub website is a bit dodgy right now. This is the website you register your app on. The website is really slow and while they have implemented ajax calls for most operations, it can take upwards of 25secs to see any results with zero indication that anything is actually loading for the user.

Having said that, there is nothing sweeter than the satisfaction of thinking that there are people out there who are using your app (and hopefully enjoying it!). I have tons of new features I'd like to add to make the app a lot more useful for others. As soon as new updates are out I'll let you know here or on my Twitter feed.

I was also a little shocked that my app went to number 1 in the Irish News section and number 6 in the overall top free downloads for the Irish Marketplace! That's pretty sweet :)

RTE News Reader app for Windows Mobile is number 1 news app in Ireland

If you want to check out the app yourself, head on over to the Marketplace and give it a whirl! I respond to all emails sent through the app so don't be shy and get in touch. I don't mind if it's good or bad. If there's a feature you'd like and I can add to the app than I'll do it :)

How to get ApplicationBarIconButton images to display

I ran into an issue the other day where I wanted to use one of the default icon set images for my new Windows Phone app. I followed the guides online and took the images from the Windows Phone SDK on my computer and pasted them into my project.

However, every time I ran my project I noticed the image was not displaying. I would just get a nice looking X in a circle (I guess it's the new "red X"!). To resolve this issue you need to right click on the icon(s) you want and select Properties. When the Property window opens change the Build Action to Content. For me, this was defaulting to Resource and was the reason that the image would not appear for me in the application bar.

IIS7 ASP Routing not working on live server

We had an issue at work the other day where one of the developers was having an issue with asp routing in IIS7. It was the first time this particular server was asked to run a .net 4 website so naturally some fine tuning was required. When we tried to navigate to the webpage the following error appeared: 403: Access Permission Denied

I thought this looked odd as all permissions were applied correct and the webpage in question was coming up for us when we included it's extension. I took a look at the web.config file and noticed the rule to use asp routing was missing so we added that:

         
    
        
        
    

However, this didn't fix our issue. I was puzzled and spent a further 30mins exploring all the different options and settings in IIS. Eventually I took a look at the Global.asax where the page routing was detailed. I noticed that there was a folder by the same name as the page we were calling. We had Directory Browsing turned off - hence the Access Denied Permission error that was throwing me off!

So I guess the bottom line is, add the above code to your web.config and if it's still not working then make sure you don't have a folder in the project with the same name that you're trying to route to!!

Entity Framework v4.2 upgrade not working

This particular error caused me some headaches so I decided to blog about it in the hope that it'll help some other poor soul! I have a pretty standard MVC 3 project that uses Entity Framework Code First for handling the database side of things. I decided to update my project to ensure it was using the latest version of all of the packages in use on my project (ninject/entity framework/etc). This particular project was using Entity Framework v4.1, which I had previously updated using NuGet without any problems, so I decided to download and install the latest version from NuGet - ver 4.2.

The Problem:

I know after installing any new version of Entity Framework it's always wise to restart Visual Studio and do a clean rebuild of your project but when I went to run this project locally it threw up the following error:

 

Could not load file or assembly 'EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.

 

It was fairly obvious that my project was looking for the wrong version of EF but I couldn't tell why. I went looking for any hard coded mention of EFv4.1 but nothing was returned. Next I did some searching online but nothing seemed to match my particular error. I took a closer look at the detailed error log and noticed it was looking for the entityframework.dll file but was not finding it.

The Solution:

I took a look in the 'Packages' folder that NuGet installs the files to. I could see 2 Entity Framework folders. One folder was for the older v4.1 and one was for the new v4.2. I took a look inside the v4.2 folder  and could see the dll files in there so I knew the files had downloaded. Then I took a look in the v4.1 folder and noticed that the folder structure was different.

  • I went back into the v4.2 folder (Packages\EntityFramework.4.2.0.0\lib\) and could see a folder called 'net40' that contained the dll files.
  • I cut the 2 files out of there and placed them into the 'Packages\EntityFramework.4.2.0.0\lib' folder (up 1 folder level).
  • I went back into Visual Studio, did a rebuild and everything went back to work for me.

Reading back over this post I can't believe how easy and simple the fix was. Up until now NuGet had always worked so it never crossed my mind that it would have botched the update. Hopefully this solution will help you out if you see that dreaded error message. Fingers crossed NuGet won't do anything like that again to me.

Dec05

New posts on the way!

Wow, it's been ages since my last post here. I've been super busy with some new exciting work over at Dragnet Systems lately which is coming to an end shortly giving me more time to post some new articles.

Over the coming weeks I'll post some articles explaining how to get the most from MVC3 for real world scenarios. A lot of my work at the moment focuses on MVC3 with Entity Framework Code First, Twitter's BootStrap and jQuery to build amazing web apps for businesses.

I've also been taking the time to learn how to setup my MVC projects to use dependency injection so that my code is much neater and tidier. It took ages to get my head around it initially but it's starting to pay off now which is great.

So there you have it. I'm still here and there will be more new posts very soon :)

How to get the id of a textbox that is using jQuery UI AutoComplete

Recently I had a need for getting the id value of a textbox that was using the jQuery UI AutoComplete plugin. I wanted to pass this id value as a parameter and use it in my Ajax call to my database. To add some extra complexity, my project was using the AutoComplete plugin on numerous textboxes. I didn't want to make a function for each textbox that would be using the AutoComplete so I had to set it up in a slightly generic way.

The trick to getting this working is to wrap your AutoComplete function call around an 'each' loop for the textboxes so that the 'attr' function becomes available to use and allows us to grab the id value we need to use in our Ajax call.

Below is the code I used. As you can see I do a 'each' call for every textbox that uses the 'tb' css class. If you've used the AutoComplete plugin before the rest of this code should be familiar to what you're using. If not, I'd recommend taking a look at the plugin documentation.

$("input:text.tb").each(function () {
        var thisElement = $(this);
        $(this).autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: "FetchLocationList/TestPage",
                    data: "{ 'loc': '" + request.term + "', 'textboxid': '" + thisElement.attr("id") + "'}",
                    dataType: "json",
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    dataFilter: function (data) { return data; },
                    success: function (data) {
                        response($.map(data.d, function (item) {
                            return {
                                value: item.Name,
                                key: item.Code
                            }
                        }))
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(textStatus);
                    }
                });
            },
            minLength: 3
        });
    });

Fix for CKEditor with MVC3 when using multiple submit buttons

I had an issue this weekend while updating some code from WebForms to MVC3 when using the brilliant CKEditor. Many of our forms display 2 submit buttons - one for publishing and one to save as a draft. When using WebForms there was never any issue with this. I'd just make 2 <asp:Buttons>, add some On_Click handlers and everything was great. With MVC3 I noticed that when using the CKEditor on my forms that I was having to click on the submit buttons twice before the page would submit.

At first I thought this was down to the MVC validation. I removed the validation but the issue still occured. "Ah, it must be the way I handle the postback with the 2 buttons!", I thought, but this didn't seem to work either. I put my button logic and the validation back on my page and removed the class I had put on the textarea of my form to get the CKEditor working and everything worked as expected. The issue was down to the CKEditor and how it was handling multiple submit buttons in a single form. You need to force CKEditor to update the textarea before carrying on with posting the page.

I did some searching on the CKEditor forums and on Google. I came across a piece of javascript that you can add to your webpage to work around this issue (asp.net forums link). Simply add the following to your page and it will resolve the '2 clicks to submit' issue you're having. Note you can add other events to this code if you want but paste and on keyup events should cover you 99% of the time.

$(document).ready(function () {
    for (instance in CKEDITOR.instances) {
        CKEDITOR.instances[instance].on("instanceReady", function () {
            //set keyup event
            this.document.on("keyup", function () { CKEDITOR.instances[instance].updateElement(); });
            //and paste event
            this.document.on("paste", function () { CKEDITOR.instances[instance].updateElement(); });
        });
    }
});

Resolve a HTTP 405 error when linking from a Facebook App

We recently had an issue of a page not loading of us once we integrated it with Facebook. This was a simple html page with nothing special on it so I was a bit confused that it would not load in Facebook for me. We were hosting the webpage on a Windows 2003 server running IIS6. Nothing fancy.

Going to the website in the browser worked great but any request coming from app.facebook.com didn't seem to be getting through. I took a look at FireBug to see what was actually being sent and received when I was calling the website from Facebook and noticed that I was getting back a HTTP 405 error. This was telling me that the calls Facebook were trying to make were not allow on my server.

I did a bit of searching on this and didn't find anything in particular about Facebook and these types of errors. However, I did notice that some people would get these errors on other web apps and the issue was down to 'html' or 'htm' file types not allowed to be called by get or posts from external requests.

To resolve the issue you need to go into IIS and right click on the domain giving you the issue and click on 'Properties'.

Next go to the 'Home Directory' tab and click on the 'Configuration' button.

Click on 'Add' on the 'Mappings' tab that just opened and either browse to the following file or enter it in the textbox:

C:\WINDOWS\System32\inetsrv\asp.dll

Type in ".html" (without the quotes) in the extension box and Limit the calls to just "GET,POST" (without quotes).

Click OK to close the popup window and again to return to the IIS domain list.

When you now view your site through your Facebook app it will appear for you without any issues.

Copy data from one table to another in the same database

There was an issue that cropped up in work today where we noticed there was a table that had been setup incorrectly that had no auto increment column for handling IDs. One of the junior developers found the bug and was telling me that he was going to export out all of the data from the table into an excelsheet, re-import the data into a new table and setup an auto increment column that way.

I guess some people just like making work for themselves :)

All that he had to do was setup a new table, let's call it TableB and give it the same columns as Table A but include an ID column and set it to auto increment and be the primary key. By running the SQL statement below, it was super quick to copy the data from one table to another. Once the data was over he could delete TableA and rename TableB to TableA.

--copy contents from Table A into Table B
Insert TableB (col1, col2, col3)
Select (Col1, Col2, Col3)
From TableA

CoolBlue BlogEngine theme now available over on BlogEngine Gallery

If you have a blog powered by BlogEngine it might be worth heading on over to the Blog Engine Gallery to see what extensions or themes you can download and use on your blog.

I was taking a look over there recently and noticed that my CoolBlue theme is now available for download in the themes section. Simply head on over to http://dnbegallery.org/cms/List/Themes/CoolBlue and click the download link. Setup couldn't be easier. Just pop the CoolBlue folder into your themes folder and you will be able to select the theme from your admin area.

The BlogEngine Gallery is a really great idea - especially now that NuGet is gaining popularity. I'm hoping to have some newer themes available over the summer and I'll definitely be using the BlogEngine Gallery to help get the themes out there for people to download.