This site uses cookies. By continuing you accept the use of cookies.I Accept

A week ago I blogged about Excel Interop in .Net. Today we released the customer solution that uses Excel Interop to create Excel files. First I want to present some new issues that we learned from when deploying this solution.

Excel Interop in a Web Application

A web application doesn’t by default use valid security credentials when running. So if you want to create some sort of Office document programmatically, you must provide a valid users Username and Password in the Web.Config. We also found other issues by doing this, and from what I’ve read it’s not recommended to do this in a Web Application. In our case we hit a dead end and started building a different solution for creating the Excel files.

Task Scheduler and Excel Interop

Our solution which is web based takes a user’s input and based on that creates an Excel file that contains an extensive report. Our “workaround” for the above issue was to create a log where every request is stored. Then we built a Windows Console Application that reads the log, creates the Excel file and sends it as an attachment in an e-mail to the person who requested the file. The Console Application is triggered every 3 minutes by the Task Scheduler.

Now we learned something new. Excel which is instantiated by the Console Application, can only run if the calling user has a Desktop folder. Since the Task Manager runs this application unattended, we have no Desktop folder.

After some digging in various forums I found the answer, and fortunately the solution.

If you run Windows Server 2008/2008 R2 in x64:
Create a folder named “Desktop” in C:\Windows\SysWOW64\config\systemprofile\

If you run Windows Server 2008/2008 R2 in x86:
Create a folder named “Desktop” in C:\Windows\System32\config\systemprofile\

The user who is declared as the running user in the Task, must have write permissions in the Desktop-folder

The final Application

The solution I’ve been writing about is Nationella Viltolycksrådet; In this web site all Swedish accidents with wild life are reported. Over 7 000 persons work daily, reporting these accidents into the system. Therefor we have access to a great amount of statistical data.

In this case the visitor can make a selection of the data he or she wants statistics for, then enter the name and e-mail address. In a few minutes the Excel file containing the reports will be sent to the e-mail address.

Try it here:

The web site is only in Swedish.



Post a comment

Post a comment