Sunday, September 5, 2010

Export Silverlight charts to MS word

Writing MS word file with Silverlight needs out of browser functionality but you can avoid this by creating a word file on server and then send this created file back to client using a HTTPhandler. This sample word export application is created using the second approach.
I have created an object oriented design for this component as I will soon extend this to a complete library for exporting Silverlight UI (chart) to DOC, XLS,PDF and other image formats.
Using the code:
  1. Place “MSWordExportHandler.ashx” and “MSWordExportHandler.cs” clientweb folder of the web application hosting your Silverlight application.
  2. Add reference to “Microsoft.Office.Interop.Excel.dll” and “Microsoft.Office.Interop.Word.dll” in you server application (web application) hosting your Silverlight application.
  3. Add reference of the component to your Silverlight project.
  4. Create an object of Export Fa├žade class in your Silverlight page like the following
  5. ExportFacade Exporter = new ExportFacade("DOC (*.Doc)|*.doc");
  6. Export your UIelement i.e Silverlight chart by calling the Exporter.Export(UIElement Chart);
  7. ExportFacade class expose two event that you optionally can capture “ExportStarted” and “ExportCompleted”
Complete snippet of the click event of export button  

 private void Button_Click(object sender, RoutedEventArgs e)
            ExportFacade Exporter = new ExportFacade("DOC (*.Doc)|*.doc");
            Exporter.ExportStarted += new ExportFacade.ExportStartedDelegate(Exporter_ExportStarted);
            Exporter.ExportCompleted += new ExportFacade.ExportCompletedDelegate(Exporter_ExportCompleted);

Sample Code


  1. Hi,
    Your Topic seems hot, but I can not download sample code from given URL:

  2. I am able to get the code. How can I get it.

  3. I am not able to get the code.. sorry about the above post

  4. Prakash,
    Please send me a mail for source at
    actually my domain is expired , so you are unable to download it from there :)


  5. There were lots of requests for source in my inbox. So, I have uploaded source for this post on sky drive as well above link for source is also updated.!106

  6. Code is not there on!106. Please upload again.


    1. Microsoft.Office.Interop.Excel.dll cannot be added as a reference in silverlight application. Please suggest, what to do.