Excel Com Interop ASP.Net Cannot write file to disk. Permissions?
I've got a pretty simple web form which lets users pick reports, one specific report they want in xls with pretty formatting instead of CSV. I've whipped up the report using COM INTEROP with excel 2007. It works on my local machine and can write the file, but on the web server it fails with this error:
Microsoft Office Excel cannot open or save any more documents because there is not enough available memory or disk space.
• To make more memory available, close workbooks or programs you no longer need.
• To free disk space, delete files you no longer need from the disk you are saving to.
There is plenty of disk space on the server, so I don't think it's that - could this be a permissions issue? I've escalated ASPNET and NETWORK SERVICE accounts to have write and开发者_StackOverflow modify access to the folder we're saving reports to - but still no joy. Any ideas?
Do I need to invoke the com object with a specific user account, or maybe elevate the interop calls to administrator account? Any idea how to do this?
Sorry guys, sorted it.
Serge you are halfway there. I ended up running Excel as administrator:
in component services, select excel application and choose admin as the user that runs it. Seems to work okay for the week of use it'll get :)
Thanks all!
SpreadsheetGear for .NET will let you save xls and xlsx workbooks directly to a response stream with IWorkbook.SaveToStream. It is all safe managed C# code so there is no need to run anything as admin and you will not run into the problems that Excel COM Interop bring on an ASP.NET server.
You can see some simple ASP.NET Excel Reporting samples (C# and VB) using SpreadsheetGear here and download the free trial here.
Disclaimer: I own SpreadsheetGear LLC
you might want to use impersonation for your ASPNET process; here's some info and example on how to do this: killing a win process from a C# console application: How do I set permissions? more info on impersonation How to implement impersonation in an ASP.NET application
精彩评论