Sudhindra Kovalam's Blog

My Geeky Blog

Posts Tagged ‘.NET 4 Roles on Azure

Using Open XML SDK v2.0 on Windows Azure

with 2 comments

Hello folks,

Its been really long that I have written a post. And I have no excuses, Just couldn’t find the right time and the right topic to blog on Open-mouthed smile.

Generating Word/Excel reports is a fairly common requirement. Now that we intend to migrate our application to cloud, we realize that on Windows Azure, You do-not have  Office DLLs or infact, any other (unnecessary from Azure’s perspective) DLLs available to you. You can always package Office DLLs with your app deployment package and use them in you application on Windows Azure (You can find articles on the blogosphere about how this can be done).

I opted for using Open XML SDK v2.0. Using Open XML SDK for .NET available here . I Can generated Word / Excel reports on the fly.

Here’s a sample code to write to create a Word Document

  
//Using Statements Required 
using DocumentFormat.OpenXml;    
using DocumentFormat.OpenXml.Packaging;    
using DocumentFormat.OpenXml.Wordprocessing;      

//Code to Create a Word Document at the provided File Path    
using (WordprocessingDocument wordDocument =
    	WordprocessingDocument.Create(filepath, WordprocessingDocumentType.Document))
    		{
   			mainPart.Document = new Document(
   				new Body(
   					new Paragraph(
   						new Run(
   							new Text("Report Generated by Open XML SDK ")))));
   			wordDocument.MainDocumentPart.Document.Save();
   			wordDocument.Close();
   		} 

ok. Now that we have everything in place, We’d want to deploy this “Report Generation Solution” to the cloud. But First , run it locally on the compute Emulator.

Everything seems to be working, Next step is to deploy your application to your azure account.

This blog post talks about a known issue on using Open XML SDK in  .NET 4 Roles on Windows Azure.

When you right click your solution to do a publish

 image

Windows Azure would ask you for the Hosted service where you want to deploy the solution, If you have not already set that up, the dialog box also has a provision to do that for you.

image

Please Remember to UnCheck, (you read that right) “UNCHECK” Enable Intellitrace for .NET 4 roles.

You may want to argue that Intellitrace helps us in historical debugging in an event  of a fatal crash, but for now you will have to live with the Windows Azure Diagnostics Logging for now.

The reason, why this needs to be disable is, “Enabling Intellitrace for .NET 4 roles when using the OPEN XML SDK seems to freeze your web/worker role.”

I Learnt this the hard way (after being billed for a week for a  (Frozen, just because I Enabled Intellitrace and am using Open XML SDK in my azure app) Extra Large VM ). In other words, that’s a lot of money. Crying faceCrying faceCrying face 

Keep reading this space for such posts to come. I am working on Windows Azure now, So I am sure there are many such topics on which I can post. Smile. Thank You.

Advertisements

Written by sudheerkovalam

February 19, 2011 at 3:38 am