Creating Excel spreadsheet

  • Thread starter Thread starter Randy
  • Start date Start date
R

Randy

Hello,
I'm getting an "Access Denied" error when I hit the line of code...

Excel.Application oXL = new Excel.Application();

From what I've read, you can get around this by putting the file (where this
code is) in a separate directory and also putting its own web.config in this
separate directory with this line in it...

<identity impersonate="true"/>

My question is simple...how can you get the .NET project (solution) to add
(use) a file not in the home directory? When I add this file (in the
separate directory) to the solution, .NET copies the file into the main
project directory and uses it.
Is there a way to do this? Am I missing something?

Thanks in advance to anyone who can help. :)
 
You should never do Office automation in a web application. There are
many other options for generating Excel content that work for most
situations.

From MS:

"Microsoft does not currently recommend, and does not support,
Automation of Microsoft Office applications from any unattended,
non-interactive client application or component (including ASP, DCOM,
and NT Services), because Office may exhibit unstable behavior and/or
deadlock when run in this environment."

http://support.microsoft.com/default.aspx?scid=kb;en-us;257757

That article also gives links to alternatives.

HTH,

Sam
 
While you can do what you're trying to do with a Windows Forms application, a
web application will only automatically look to resolve assembly references
in only a couple of places. The bin directory (and any subdirectories) and
the GAC. If you have the class placed into COM+, ASP.NET will find it there
too, but I believe that the COM+ assemblies are in the GAC, so that doesn't
really could.

That having been said, I don't know for sure if that is your problem. I
believe I've seen access denied errors in this situation where the ASP.NET
user hadn't been granted Launch permissions for Excel. You would be able to
grant this permision using the DCOM Config tool.

Hope that helps.

Bruce Johnson [C# MVP]
http://www.objectsharp.com/blogs/bruce
 
Randy said:
Hello,
I'm getting an "Access Denied" error when I hit the line of code...

Excel.Application oXL = new Excel.Application();

From what I've read, you can get around this by putting the file (where
this code is) in a separate directory and also putting its own web.config
in this separate directory with this line in it...

<identity impersonate="true"/>

My question is simple...how can you get the .NET project (solution) to add
(use) a file not in the home directory? When I add this file (in the
separate directory) to the solution, .NET copies the file into the main
project directory and uses it.
Is there a way to do this? Am I missing something?

Thanks in advance to anyone who can help. :)
This has nothing to do with code file locations, the web application
identity (aspnet or the impersonating user) has no rights to start and
access Excel.
You need to run dcomcnfg and grant Launch and Access privileges to the
aspnet user for Excel.
Note that you shouldn't use impersonation here as you'll have to include all
possible users to the list.
Note also that using Office applications from web applications isn't
supported and (in general) doesn't work as you would expected, Office is a
personal productivity tool to be used from a client, it isn't designed to
run server side.

Willy.
 
what are you trying to do with excel? maybe there is a better way

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc, Amazon.com etc
 
Back
Top