White Christmas Piano Song

Christmas is coming everyone!! Merry Christmas ^_^

SharePoint 2007 list item print button with SSRS reportviewer

Recently I was tasked to migrate the old Asset data on Access db to SharePoint 2007. It's not difficult using 'Export to Sharepoint List' command and modified certain things such as creating new asset content type, site columns etc.

I can view the list and the items. Great. but there is no print button! In Access db, they were using Access form to print the asset item. In SharePoint 2007, turns out that I have to do a bit of development to do just that.

I found the nice blog on how to do this. However, I don't want to spend ridiculous amount of time playing with HTML markup to get the design I want. It is error-prone as well in terms of printing etc.

Therefore, I decided to try using Reporting Service reportviewer control on the page that will render the layout. The list item details will be passed as parameters :) Cool!

If you search google, you would find many articles about passing the parameters in the URL. this is not good since you will get ugly url and it will give you limitation in size. By exposing the 'custom action' into a list 'content type', we can get the List and ID to work with (mentioned in the above blog).

Enough of the theory, let's see how we can get this going:
1. Design the SSRS report (uh-huh). Add the parameters for each of the list item column you want to include.

2. Upload it to your report server. Then your report is ready for our printing page to consume :)

3.If you follow the blog to add a print button, you should have the button in your list dispform.aspx now! Except that inside the body tag of the print.aspx, we use the reportviewer control :

4. On your code behind (or inside a script tag if you don't want any code behind), get the report from the server and pass the parameters into the Report in the load event:

5. Notice that you need to provide ReportServerCredentials and set the ProcessingMode to Remote. This will ensure that you don't get the nasty 401 Unauthorized Error. The ReportServerCredentials class is listed below:

6. Also don't forget to check if your ReportViewer handlers exist in your web.config:

7. When you successfully deploy your feature, the print button now will take you to the print.aspx and the page will display your report like this:

I hope this article will help you someday :)

.NET Convert Word Document into PDF


I came across this old code of converting Word into PDF:

This used to work well until recently the avdoc object sometimes doesn't get the instance (i.e. null) , however running it twice usually fixed it.

I don't know what caused this. It might be a system update or something. I also researched that the above code shouldn't even work since it's using Acrobat interop to open a 'doc' type - so that code was kind of a hack.

To fix the issue, I decided to find alternative way of converting word to PDF pro grammatically. This other way requires office 12 interop instead. So the idea is to open the doc in office and save it as PDF. Simple enough! here is the code:

P.S: Don't forget to install Office2007 and Acrobat on the machine :) enjoy!

Starlight - New Piano Composition

Here you go:

Hope you enjoy it :)

Load and Deploy XAP into Silverlight Application through MEF Deployment Catalog

What a sunny day today, and it feels brighter when everything comes into place together. Fortunately, this is also the case for MEF (Managed Extensibility Framework).

At first I could not really be bothered with learning this stuff, however I found out that this framework is what I will be needing most for my project! Why? because MEF has the ability to join every piece of functionality together!

Managed Extensibility Framework

It basically contains three steps that you need to implement:
  • Export : this can be any class, interface, or objects that you want to export.
  • Import : This is the place where you can get the exported pieces and do stuff with them.
  • Composition : Imagine this as a connector between export and import. It basically compose any/all parts that you specify in export and make them available for the import.

In MEF, a piece of functionality is described as a catalog. The new deployment catalog (which I'm going to be using) is very flexible in terms of adding and removing external functionality in your application.

For more information, you can read Glenn Block posts. I will also use his deployment catalog service for easier XAP adding/removing.

Real Example - Embedding Bible Application into Silverlight Business Application

No, this won't be a difficult demo and No, this won't be a Hello World example. I like showing people a real example of situation that you might encounter in the real world.

For that purpose, I will be embedding my simple Indonesian Bible application that I wrote into Silverlight Business Application.

So the idea here is that I have built a Silverlight application and I want to just load that in my main business application. This is really cool, especially if you want to organize your source code in a neat manner. MEF really can provide you with plug-in architecture.

Let's get started then! :)

I need to add little piece of code into my bible application. To be able to let other application to import my bible, I need to make this application available. Therefore I need to add the export attribute.

Here I just export the usercontrol of my application. Don't forget to add to the MEF reference System.ComponentModel.Composition located in C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Libraries\Client\System.ComponentModel.Composition.dll

Rebuild the project.

In other posts, they built the application in the same solution as the host. In my case, I don't want to do that. The only thing MEF worry about in Silverlight is that there is an external XAP file in ClientBin directory of the host.

For this demo, I am just going to copy paste the XAP in the previous section (after the rebuild) into the ClientBin directory of the Silverlight Business Application.

Also, add the System.CompositionModel.Composition and System.CompositionModel.CompositionInitializer to the host application. I will then do the import inside my Home page of the host.

To do this, in Home.xaml I create an ItemsControl that will load the imported usercontrol and bind it to a property of the view model:

The home view model is like this:

Here I use ImportMany and set AllowRecomposition to True. This indicates that we can import more widget as they are available. Also the recomposition is automatically done for you when there is any change in the composition.

I won't explain the Lazy declaration as Glenn Block explained it well in his blog.

Composition - Deployment Catalog

The DeploymentCatalogService is this:

Thank you Glenn for posting this!

Here are the steps to make things connect together:
1. In App.xaml.cs, call DeploymentCatalogService.Initialize(); inside Application_Startup

2. In my home.xaml.cs, I call the SatisfyImports, and add the external XAP using the DeploymentCatalogService. When user is navigated away from the page, I remove the XAP to avoid conflict of adding an existing XAP to the application.

Hooray. Now when I run my Silverlight Business Application, my bible application will load inside my home page.

Thanks for reading this and I hope you would find it useful ^_^

Hosting WCF Service 4.0 in IIS 7.5

Hi Everyone,

Today I want to show you what I did to get my WCF Service hosted on my development machine IIS (this could be your web server too). I am using VS 2010, .NET 4.0 framework, and IIS 7.5 in Windows 7 environment.

In this demonstration I am going to use my AlkitabWebService.svc found in this post: Silverlight 4 Simple Project Part 2 (WCF Service).

Step 1 - Enabling IIS + ASP.NET Registration
  • Click Start -> Control Panel -> Programs -> Programs and Features.
  • On the left tab, click Turn Windows Features on or off. Turn on the features below and click OK.

  • When you go to http://localhost , you will now see the IIS7 homepage.
  • Now go to a command prompt and run aspnet_regiis:

Step 2 - Publish the WCF service from VS 2010
  • Right-click the project and click Publish.
  • Choose 'File System' as Publish method, and type C:\inetpub\wwwroot\AlkitabWebService\

This will create a folder for your WCFService that you can refer to from IIS in the next step.

Step 3 - Create New Application in IIS
  • Go to your IIS Manager (can be accessed from Administrative Tools).
  • Right-click Default Web Site -> Add Application...
  • Enter in the Application Name and point the physical path to the folder that contains our published WCF service.

Step 4 - CrossDomain.xml and ClientAccessPolicy.xml
  • In order to be able to access your localhost in IIS, you need to implement a cross domain policy. I'm just going to make this simple. In your C:\inetpub\wwwroot folder, create a crossdomain.xml and clientaccesspolicy.xml files:

  • Crossdomain.xml

  • Clientaccesspolicy.xml

Step 5 - Test your WCF Service
  • In IIS Manager, click the AlkitabWebService (alias).
  • On the right tab, click Browse*:80 to go to your http://localhost/AlkitabWebService/
  • You should get the view like this:

  • Clicking on AlkitabWebService.svc is our Service page. Yay!

Silverlight 4 Simple Project Part 4 (Binding & Command)

Silverlight 4 Simple Project Part 3 (MVVM Pattern)

This is the last part of the blog (finally :P).

In the previous post we already created our MVVM. How do we connect our View to the ViewModel? Easy! There are couple of ways to do this. We can do it declaratively in XAML or we can do it in the code-behind.

View - View Model & Binding

I will choose the first option.

Looking at the XAML snippet above, we declare our ViewModel as a User Control Resource and set the DataContext of our main grid to that resource.

Having done that, now we can easily do our data binding for our user elements.

How cool is that? We don't need any code-behind at all for our XAML! This is the beauty of MVVM Pattern.

Now when we select our book title, chapter, or verse, we will get our results back in the grid without any postback since all calls are made asynchronously.


Another new feature in Silverlight 4 is the built-in Commanding option. In this project, if you look at the image above, there is an 'Enable Range' button. I attached a command to this check box so that when IsChecked is True, it will enable the SelectBookVerseEnd selection. If IsChecked is False, it will disable the combobox.

The SelectBookVerseEnd property will in turn decide whether we call the GetAlkitabSnippet function (single AlkitabSnippet object) or the GetAlkitabSnippets function (multiple AlkitabSnippet objects).

Notice that I use UI Element to Element binding between the IsEnabled property of the combobox and the IsChecked property of the checkbox.

To make the commanding easier, I am using the DelegateCommand class (put this inside your ViewModel) that implements the ICommand interface. This class will have the Action and CanExecute parameters that are required by the interface.

If you look at the XAML, the command of the checkbox is bound to DisableRangeCommand.
Lets look at how the commanding is implemented in our view model

and that's it! Simple is that. Commanding enables MVVM pattern since we don't require to handle the UI event in the XAML code behind.

I will post the solution later on. Thanks for reading this and I hope you will find it useful for your own purposes.



Silverlight 4 Simple Project Part 3 (MVVM Pattern)

Silverlight 4 Simple Project Part 2 (WCF Service)

In Part 2 we already created our WCF Service that can return some results to us when functions are called.

In this post I will start building my Silverlight Application :)

Silverlight Project

Create new project inside the same solution. Choose Silverlight Application and name it AlkitabApplication. Right-click the project and choose Add Service Reference. click Discover and you can see that our AlkitabWebService.svc is shown. Easy!

In the above picture you can also see that I created three new folders called Model, ViewModel, and Views. Move the MainPage.xaml to the Views folder.

Model View View Model (MVVM) Pattern

For those who are new to this term, you can read this. Otherwise you might want to move on.

MVVM is just a pattern. There is no strict procedure on how to implement it. This pattern is created for developers to separate the logic of their application, providing a nice way to do unit testing and creating blendability between designer <-> developer.

What this means is that designers can focus on playing around with the Views and developers can provide back-end data in the View Model (that perform queries against the Model) independently. The View can then just hook the View Model into it and create the bindings between the UI Elements <-> data. Moreover, developers can provide designers with dummy data to test while designing the Views.

People have been creating tools and frameworks to assist this pattern, such as MVVM Light, MEF, and Prism. However, I won't be using any of those since my application is really simple.

Confused? Let's see in action!


Rather than calling WCF Service straight in our XAML code behind, we will create a class called AlkitabService.cs in our Model folder. It is nice to have a high level layer that provides us with one logical purpose: Our Data Source!

This class will provide us sets of functions that call WCF Service functions asynchronously. Asynchronous call is what Silverlight is all about right? :)


I am not much of a designer, but I like clean design :) Here is what the application looks like:

I won't show you the XAML just yet because I will show it when I'm doing the bindings. In this project I am using Telerik Silverlight controls (RadComboBox and RadGridView). Simple reason, they have nice features such as Auto-Complete, Filtering, etc. However you can use the normal Silverlight controls to do the same thing.

View Model

Here is the main player. This is where all the logic resides. Inside the folder, I created two classes: ViewModelBase.cs and AlkitabViewModel.cs

ViewModelBase is just a base class that implements INotifyPropertyChanged. Remember that all data/properties exposed in the UI need to have this event raised to notify the UI elements.

Inside AlkitabViewModel.cs is where we call our Model and store the data into our class properties that we can then bind to our UI.

Notice that we raise the NotifyPropertyChanged event in the setter of all properties.

I hope you don't get a headache from this. In the next post I will talk about hooking up our ViewModel to our Views and perform the bindings. I will also quickly explain the Commanding in Silverlight 4.

Silverlight 4 Simple Project Part 4 (Binding & Command)

Silverlight 4 Simple Project Part 2 (WCF Service)

Silverlight 4 Simple Project Part 1 (Overview & Database)

Here I will create a WCF Service as a middleman for our Silverlight <-> Alkitab Database that I mentioned in Part 1.

New Project & LINQ to SQL

To start, I will create a WCF Service Application from Visual Studio 2010 (I didn't choose WCF Service Library because we will host it as a 'web' application in the future).

Then right-click the project, Add New Item -> LINQ to SQL Classes. We want to drag our two tables from the Server Explorer into the dbml file. This will provide us the DataContext we require for performing our queries.

WCF Service

Next, rename Service.svc and IService.cs to friendlier names like AlkitabWebService.svc and IAlkitabWebService.cs

IAlkitabWebService.cs is the interface class for our service. This will hold all the OperationContract (functions) declarations and any DataContract (web class) that you want to create along with its DataMember (class property). Here I have sets of operations and AlkitabSnippet class that will hold verse and content:

public interface IAlkitabWebService
string GetContent(string bookTitle, int bookChapter, int bookVerse);

ObservableCollection<AlkitabSnippet> GetAlkitabSnippet(string bookTitle, int bookChapter, int bookVerse);

ObservableCollection<AlkitabSnippet> GetAlkitabSnippets(string bookTitle, int bookChapter, int bookVerseStart, int bookVerseEnd);

ObservableCollection<string> GetBookTitles();

ObservableCollection<int> GetBookChapters(string bookTitle);

ObservableCollection<int> GetBookVerses(string bookTitle, int bookChapter);

// Use a data contract as illustrated in the sample below to add composite types to service operations.
public class AlkitabSnippet
string verse;
string content;

public string Verse
get { return verse; }
set { verse = value; }

public string Content
get { return content; }
set { content = value; }

In the AlkitabWebService.svc.cs, we implement all the service functions that we need to get data out of the database. Here are two of the functions:

public class AlkitabWebService : IAlkitabWebService
public ObservableCollection<AlkitabSnippet> GetAlkitabSnippets(string bookTitle, int bookChapter, int bookVerseStart, int bookVerseEnd)
ObservableCollection<AlkitabSnippet> snippets = new ObservableCollection<AlkitabSnippet>();

AlkitabDataContext db = new AlkitabDataContext();

var query = from c in db.Alkitabs
join b in db.AlkitabBooks
on c.book equals b.bookno
where b.booktitle == bookTitle && c.chapter == bookChapter && c.verse >= bookVerseStart && c.verse <= bookVerseEnd
select new { verse = c.verse, content = c.content };

foreach (var e in query)
AlkitabSnippet snippet = new AlkitabSnippet();
snippet.Verse = bookTitle + " " + bookChapter + ":" + e.verse;
snippet.Content = e.content;

return snippets;

public ObservableCollection<string> GetBookTitles()
ObservableCollection<string> booktitles = new ObservableCollection<string>();

AlkitabDataContext db = new AlkitabDataContext();

Table<AlkitabBook> AlkitabBook = db.GetTable<AlkitabBook>();

var query = from a in AlkitabBook orderby a.bookno select a.booktitle;

foreach (var e in query)

return booktitles;

One question you might ask (I asked this to myself as well when I was a total newbie) is what is an ObservableCollection. WCF Proxy Class use this type of collection by default. However, this collection is different from other type of normal collection, lets say List, in a sense that it provides notification when items get added, removed, or refreshed and when the items property is changed (it implements INotifyCollectionChanged and INotifyPropertyChanged).

This is required for Silverlight to get the notification any change so that it can update all the UI elements associated with the collection.

That's all we need to do for our WCF Service :)

In the next post we will create our Silverlight application that references this service. I will start with the explanation of MVVM model, the popular pattern of building your application.

Silverlight 4 Simple Project Part 3 (MVVM Pattern)

Silverlight 4 Simple Project Part 1 (Overview + Database)


This will be my first technical blog. The motivation behind this is that I love learning Silverlight (and it's version 4 now!). So I decided to create my own simple project as I am thinking of building a website for my church community group in the future.


Why not start with a simple module? I want to be able to search for a bible verse in a quick way and no hassle of having to spend much time on it. Therefore I want the users to be able to select the book title, chapter, and verse (or verse range) and have the contents showed in front of them straight away!

Here is a video showing the completed application with some explanation:


Now.. I found out that there are already some English bible web services out there. However since my community is Indonesian, I want to have an Indonesian bible, and it turns out that there is none! and there is no SQL formatted database dump available either :(

However, I could find the text format of the bible. I looked inside and here is what it looks like:

'This must be my day', I said to myself; This is because I could easily do this:

And just use bulk insert to load the txt file (Alkitab = Bible):
FROM 'c:\IndonesianBible.txt'

Nice. Now I have my Indonesian bible database. To improve my database, I am going to create another table that contains my book title and link both tables together:

In the next post I will create a WCF Service with some functions that will query this database and return the contents that will be consumed by our Silverlight application. :)

Silverlight 4 Simple Project Part 2 (WCF Service)

My Piano Songs - Blog Started!

Hello Everyone,

As I am starting my blog, I want to entertain you all with few of my popular songs. Feel free to listen to all of them and give any feedback! ^_^

Here you go:

1. Rising

2. Winter Love

3. The Truth

I will probably post my other songs regularly. I will also post my YouTube videos here as well. Feel free to follow my blog :)

Thanks and Enjoy!