Weblog API in Umbraco: Word to Umbraco

In one of my recent projects my client asked if it was possible to create and update content directly from Word as he’s primarily writing news and articles in Word from his mobile phone (HTC with Windows OS) First off, I thought that it would be quite a complex task, but my fellow Umbraco developer, Morten Bock gave me a hint about Word supporting the MetaWeblog API. I read up on it and it seemed pretty straight forward to make us of with Umbraco.

So I set it up like this:

  • Add a content channel on the Umbraco user:

  • Create a new Blog account in Word

  • Start writing content

A fairly simple approach indeed!

However, I ran into a beautiful, self-explanatory error in Word when I tried to add the Umbraco channel:

Since the current Umbraco had been upgraded to 4.5.2 from the passwordFormat attribute in the membership provider section of the web.config file was still set to “Hashed”, I changed this to “Clear” and changed the hashed password directly in the database (table: UMBRACOUSER) and it worked right away.

So, basically if you receive the error above, you should check to see if the password is hashed both in the database and in the web.config aswell.

Happy publishing! ;-)

Posted in Umbraco CMS | Tagged , | Leave a comment

Notify members by email

The last week I have been working on a medium sized Umbraco project where you, as a member of the site, is able to advertise yourself and/or your product(line). When an ad is created, it’s set to expire at a given date set by the administrators. One of the business problems in this project was, that members had to be notified by e-mail x days before their ad expires. Since this is not implemented directly in the Umbraco API, I had to come up with a custom solution to this problem.

This is how I did it:

  1. Define the document types needed
  2. Build a .NET UserControl
  3. Install Richard Soetemans TaskScheduler plugin (http://our.umbraco.org/projects/developer-tools/taskscheduler)

First off, let’s take a look at the document types. I created three document types for this:

  • A ‘container’ called i.e. ‘Ads’ for holding all the ads
  • The actual ad which contains the following properties: isAdActive (true/false), isNotified (true/false), adPeriod (Date Picker with time)
  • A ‘Notify settings’ type which contains these properties: daysBeforeNotification (Numeric), numDaysForActiveAd (Numeric)

To sum up these document types: the ‘Ad’ has ‘isAdActive‘ which defines if the given ad is active on the frontend, ‘isNotified‘ tells us if an e-mail for the ad has already been sent and ‘adPeriode‘ tells us the actual period for the ad. The purpose for the Notify settings document type is to let administrators control the amount of days before sending an e-mail and determine how many days the ads are active.

Next up, let’s have a look at the ASP.NET UserControl I made for this:

First, we have to remember to add a reference to the umbraco.dll, cms.dll and businesslogic.dll. These can be found in the bin folder of a fresh umbraco download.

Then we need to get a reference to the Notify settings node which we do like this:

Step two: get all active ads and check if a notification has already been sent:

If the ad is active and no notification has been sent yet, we may proceed. Note that the true/false boolean datatype in Umbraco does not return true or false, but instead it returns 1 (for true) and 0 (for false) ,so we have to check these with the string Equals() method.

Next, we have to make sure that the expirationDate is actually set to a value before we proceed:

If the expirationDate string contains a value we need to parse it to a DateTime object. Also we need to make a new DateTime object which contains the value of the currentdate. Then we need to calculate the difference between these two dates using a TimeSpan object and if the difference (in days) is equal to the number of days specified by the administrator(s) we will proceed. We need to know which member the ad is related to, so by using the relationship API (I’m using Hendy Rachers Relation Type package which can be found here: http://our.umbraco.org/projects/developer-tools/relation-types) in Umbraco, we get the reference to the specific relation type: member2ad (which is a member (parent) to document (child) two-way relationship) When the related member has been found, we will set the isNotified datatype to 1, to let the Task Scheduler know that an e-mail has been sent to the member.

Last, we will call a seperate method to actually send off the notification e-mail where, in this case, we will pass the e-mail and the header of the ad to the method. The header will be a part of the topic in the e-mail to let the member know which ad is about to expire.

All we need to do now, is to place the UserControl on a page that is hidden from the frontend users/visitors (simply set the umbracoNaviHide property to true). In the TaskScheduler package you can point the scheduler to this page and set when and how often the scheduler will perform a visit to the page. Like this:

And that’s basically all there is to it. As you can see on the above screenshot, you can even set the scheduler to perform this check every hour if you need to.

Mind you, there is a flaw in this solution: if there is absolutely no traffic at all to your site (which is highly unlikely, but this is worst case!) The umbraco application will ‘go to sleep’ and therefore the scheduler will not perform the check before the application has been started again (when the page has been visited). If you reach worst case, that there’s no traffic at all, you could simply use an uptime service to ping your site – i.e. a cronjob.

Feel free to discuss this solution – I bet this is just one way to solve this problem!

Posted in Umbraco CMS | Tagged , | 2 Responses

Hello world!

Well, hello world!

Finally I decided to get something up and running here at my personal site (or was it just a plain good excuse to play around with WordPress, maybe?) Anyway, here I’ll be blogging and babbling about myself, my business, ASP.NET, Umbraco and webdevelopment in general.

Maybe, just maybe, I will toss a few posts about graphic design guidelines in Photoshop and/or Expression Blend for XAML based solutions. Stay tuned! :)

Posted in ASP.NET, bo-mortensen.dk, uconsult, Umbraco CMS | Tagged , , | Leave a comment