Wrox Programmer Forums
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 13th, 2004, 07:38 AM
Authorized User
 
Join Date: Jul 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default accessing word

hi i'm trying to access word from asp.net, using vb.net and IIS 5.1. I am just trying to instantiate a new document, but i keep getting an error. My code is as follows:
<code>
Dim objWord As Word.Application
Dim objDoc As Word.Document
objDoc.Add()
</code>

the error i get is as follows. Anyone got any ideas?:

Object variable or With block variable not set.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object variable or With block variable not set.

Source Error:


Line 50: 'objDoc.Add("C:\text.doc")
Line 51: 'objDoc = New Word.Document
Line 52: objDoc.Add()
Line 53:
Line 54: End Sub


Source File: c:\inetpub\wwwroot\tripreportasp\WebApplication1\W ebForm1.aspx.vb Line: 52

Stack Trace:


[NullReferenceException: Object variable or With block variable not set.]
   Microsoft.VisualBasic.CompilerServices.LateBinding .InternalLateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack, Boolean IgnoreReturn)
   Microsoft.VisualBasic.CompilerServices.LateBinding .LateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
   WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\tripreportasp\WebApplication1\W ebForm1.aspx.vb:52
   System.Web.UI.Control.OnLoad(EventArgs e)
   System.Web.UI.Control.LoadRecursive()
   System.Web.UI.Page.ProcessRequestMain()





 
Old December 13th, 2004, 07:49 AM
Authorized User
 
Join Date: Aug 2003
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Though you dimensioned the variable: objDoc you never instantiated it.

You need to add the code:
objWord = new Word.Application
objDoc = new Word.Document

Honestly, I'm not positive about hte syntax here. I've been writing in C#.

I've had NIGHTMARES trying to instantiate Word from the old ASP due to permissions.
It seemed that the only way I could do it was to give the IUSER_MYComputer (in this case it would be the DOT NET user) full control over all the directories on the computer.

If you get this working PLEASE let me know how you got the permissions to work.
Marl Atkins - [email protected]

 
Old December 13th, 2004, 10:53 AM
Authorized User
 
Join Date: Jul 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi marl,
thanks for the response. I tried this and am getting permissions errors too.

Access is denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access is denied.

I tried giving ASPNET full permissions on the C: drive but its still giving me this error... any more ideas?


 
Old December 13th, 2004, 06:27 PM
Authorized User
 
Join Date: Jan 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to rathbird
Default

If you're just trying to open a blank word doc, use this client side code (you can run it on any event):

<html>
  <head>
    <title>WebForm2</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name=vs_defaultClientScript content="JavaScript">
    <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
    <script language=javascript>
        function startApp(myAppName)
        {
            var myApp = new ActiveXObject("WScript.Shell");
            if (myApp != null)
            {
                myApp.Run(myAppName);
            }
        }
    </script>
  </head>
  <body onLoad="javascript:startApp('WinWord.exe')">

    <form id="Form1" method="post" runat="server">

     </form>

  </body>
</html>

Now, it does display a dialog asking to allow ActiveX interaction. The only way to get around this is to have your app be a trusted site and to allow trusted sites to permit ActiveX objects, which is a security breech. I'm fine having the dialog pop up.

 
Old December 13th, 2004, 06:55 PM
Authorized User
 
Join Date: Aug 2003
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If all you're trying to do is pull a Word doc into the browser you don't even have to create an ActiveX object (for the IE browser anyway).

You can call a URL that is simply a Word Doc.
Ex. http://www.MySite.com/MyDocs/MyWordDoc.doc.

The browser will open the doc.


 
Old December 13th, 2004, 06:59 PM
Authorized User
 
Join Date: Aug 2003
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There is such a thing as DCOM which is 'Distributed Component Object Model'. You can get to it by typing in your Windows>>Start>>Run:
dcomcnfg. That should pull up the interface that lets you set permissions for DCOM which is required to access a Word Doc.

You'll have to play with it a bit but in general, make sure that the DotNet user has permissions to access it.

I could be more specific but I just don't remember the details.
Hope that helps.

 
Old December 13th, 2004, 07:04 PM
Authorized User
 
Join Date: Aug 2003
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh, one more thing before I put this to bed.

If you try to use the ActiveX object routine you'll find that MS Internet Explorer 6 has a default of simply DENY. The popup won't give you the option to access it. You've got to manually reset the Security level in the browser before the popup will let you access ActiveX at all.



 
Old December 14th, 2004, 05:40 AM
Authorized User
 
Join Date: Jul 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks guys, i got the permissions to work late yesterday, but now i'm having another problem, in that i can't seem to access word.documents it won't compile. is there something that i have to make a reference to or to import to use this?

 
Old December 14th, 2004, 08:27 AM
Authorized User
 
Join Date: Jul 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hey guys, thanks again for your help, i've got it working now!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing Word through ASP.NET renoldr General .NET 2 December 2nd, 2013 06:58 AM
Creating word doc - word behaviour mat41 Classic ASP Professional 2 April 29th, 2007 06:46 PM
Accessing WORD object in ASP mcinar Classic ASP Basics 5 March 30th, 2005 04:19 PM
Accessing Word Object Library from .NET Web app debsoft General .NET 3 April 21st, 2004 05:53 AM
Accessing word document from VB Prasanna VB How-To 3 January 20th, 2004 05:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.