Opening MS Word from a VB.NET ASP application

Y

Yohancef Chin

Hi,

Being fairly new to .NET I am looking for a way to call MS
Word from an event on a webform, and after the user is
finished save that created document to an SQL Server
database. Has anyone done this? Does it seem possible? I
followed the instructions from a sample on the Microsoft
knowledge base but it only seems to work when creating a
VB.NET Windows .EXE, not an VB.NET ASP app.

Imports Word=Microsoft.Office.Interop.Word

Dim oWord As Word.Application
Dim oDoc As Word.Document


'Start Word and open the document template.
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add

I changed the sample code to the following:

Dim oWord As Word.ApplicationClass
Dim oDoc As Word.DocumentClass


'Start Word and open the document template.
oWord = New Word.ApplicationClass()
oWord.Visible = True
oDoc = oWord.Documents.Add

But when i build the solution it gives me the following
error:

Access Denied

Exception Details: System.UnauthorizedAccessException:
Access is denied.

The ASP.NET process is not authorized to access the
request. For security reasons the default ASP.NET process
is '{machinename}\ASPNET' which has limited privileges.
Consider granting access rights to the resource to the
ASP.NET process identity.

Line 31: oWord = New Word.ApplicationClass()

But it does not specify what it is trying to gain access
to. I tried giving the asp account admin rights just to
test but that didnt work. I also lowered to security
settings on IE to test as well, and I gave the ASPNET
account full access to the
Microsoft.Office.Interop.Word.dll.

Any ideas?

Thanks.
 
A

Andrea D'Onofrio

Server-side office automation is not supported by Microsoft, in this article
you'll find the best way to configure the environment in this scenario:
INFO: Considerations for Server-Side Automation of Office

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

These article explain how to create an office document server-side in a
supported way:
http://support.microsoft.com/default.aspx?scid=kb;en-us;288130

http://support.microsoft.com/default.aspx?scid=kb;EN-US;311461

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


These articles explain how to automate office application using client-side
code:
178222 HOWTO: Launch Word from Internet Explorer

http://support.microsoft.com/?id=178222

183284 INFO: CreateObject in VBScript

http://support.microsoft.com/?id=183284

209149 WD2000: How to Pass a Parameter to a Macro Using Automation

http://support.microsoft.com/?id=209149

285176 HOWTO: Automate Word to Perform a Client-Side Mail Merge Using XML
from

http://support.microsoft.com/?id=285176

HtH

Andrea
 
F

Francis Dion

Hi,

As Andrea says, Server-side office automation is "doable" but really
not recommended.

You might want to look at XpertDoc, a fast and reliable technology
designed specifically for server-side, unattended creation of genuine
MS-Word documents.

It is very easy to set up, requiring little or no programming and
configuration.

You can download a free evaluation copy from www.xpertdoc.com

Hope this helps!
 
E

Elizabeth Harmon

Yohancef

the access denied is a dcom thing with windows and you will have to go into
your dcomcnfg, click start run and type dcomcnfg.exe. Say No to the popups
that come up. Once the Windows Opens, find the listing for Microsoft Word
Document, Click Properties, and change the setting in the Identity Tab to
use an interactive user.

I am doing the same thing as you and have gotten really excellent advice
from this news group, look for my Name in the Postings and you
May see the Same Advice i got to fix this problem.


hope this helps

Samantha
 
Joined
Jan 29, 2009
Messages
1
Reaction score
0
It does not seem to be an issue with the automation application you are writing. You must have tried the same application locally before deployment to the server.

Please, check for the permissions on server for the user by which you log-in for deployment. Hope it helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top