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:
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);
Exporter.Export(crtChart);
}
Sample Code
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:
- Place “MSWordExportHandler.ashx” and “MSWordExportHandler.cs” clientweb folder of the web application hosting your Silverlight application.
- Add reference to “Microsoft.Office.Interop.Excel.dll” and “Microsoft.Office.Interop.Word.dll” in you server application (web application) hosting your Silverlight application.
- Add reference of the component to your Silverlight project.
- Create an object of Export Façade class in your Silverlight page like the following
- ExportFacade Exporter = new ExportFacade("DOC (*.Doc)|*.doc");
- Export your UIelement i.e Silverlight chart by calling the Exporter.Export(UIElement Chart);
- ExportFacade class expose two event that you optionally can capture “ExportStarted” and “ExportCompleted”
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);
Exporter.Export(crtChart);
}
Sample Code
Hi,
ReplyDeleteYour Topic seems hot, but I can not download sample code from given URL: http://www.abubakardar.com/blogcodes/SilverlightExport.rar
I am able to get the code. How can I get it.
ReplyDeleteI am not able to get the code.. sorry about the above post
ReplyDeletePrakash,
ReplyDeletePlease send me a mail for source at abubkr.dar@gmail.com
actually my domain is expired , so you are unable to download it from there :)
thanks,
Abubakar
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.
ReplyDeletehttps://skydrive.live.com/redir.aspx?cid=8e18b61e7a140d6f&resid=8E18B61E7A140D6F!106
Code is not there on https://skydrive.live.com/redir.aspx?cid=8e18b61e7a140d6f&resid=8E18B61E7A140D6F!106. Please upload again.
ReplyDeleteThanks,
Sachin
Microsoft.Office.Interop.Excel.dll cannot be added as a reference in silverlight application. Please suggest, what to do.
Delete