469,953 Members | 2,235 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,953 developers. It's quick & easy.

Creating Excel spreadsheet

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. :)
Nov 17 '05 #1
4 3060

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...b;en-us;257757

That article also gives links to alternatives.

HTH,

Sam
On Fri, 13 May 2005 13:07:44 -0500, "Randy" <te**@temp.com> wrote:
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. :)


Nov 17 '05 #2
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" wrote:
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. :)

Nov 17 '05 #3

"Randy" <te**@temp.com> wrote in message
news:uy****************@TK2MSFTNGP09.phx.gbl...
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.


Nov 17 '05 #4
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
"Randy" <te**@temp.com> wrote in message
news:uy****************@TK2MSFTNGP09.phx.gbl...
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. :)

Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by volume | last post: by
3 posts views Thread by A.M | last post: by
9 posts views Thread by Gordon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.