View Full Version : open Word document with VB.net
reverendleo
08-08-2005, 11:05 PM
Greetings!
I'm having trouble finding the correct way to open a Microsoft Word document with asp.net (VB). I read something about adding a COM reference to the Word Object Library (or something of the sorts), but the example uses Visual Studio, and I am working in Dreamweaver. If it's a matter of importing the correct namespace, I'm not sure which one to use. Otherwise, I'm at a loss.
Here's the procedure code I have so far:
Dim appWord As New Word.Application
Dim docWord As New Word.Document
docWord = appWord.Documents.Open("L:\SWPPP\SWPPPBookMerge.doc")
Further more, I'm hoping to merge data from a table into this document, but I figured opening it would be a good first step.
Thanks in advance!
B. Drake
Roelf
08-09-2005, 08:37 AM
Your code should work, make sure the asp.net user (is a technical user) has started MS Word once (otherwise the msi package for Word will try to launch and that fails most of the time) AND make sure the location of the file (L: looks like a mapping to me, so the user has to be able to get access to that drive, better use UNC paths (like \\servername\sharename\dirname\filename.doc)) to make sure it is user independant
good luck!
reverendleo
08-09-2005, 04:20 PM
Thanks for the advice!
However, I can't even get it to compile without errors, as it doesn't recognize Word.Application or Word.Document.
If it's a matter of adding the correct namespace, I'm not sure which one I need. Is there something that has to be configured on the server to add the Word Object Library or something of the sorts?
Much obliged.
Roelf
08-09-2005, 04:36 PM
Imports Microsoft.Office.Interop
reverendleo
08-09-2005, 05:07 PM
Beautiful, thank you sir.
I'm still getting an error on compiliation:
Type 'Word.Application' is not defined.
I thought the imports would fix it, but appearantly not.
I've put the Imports statement at the top of the page with the other
<%@ import Namespace="...... statements, but no dice.
Any ideas?
Appreciate it!
Roelf
08-09-2005, 08:50 PM
Which office version are you using?
If it is office 2003, the Imports should work, if it is an older version, you should first create a com reference. Don't know how dreamweaver works on that area.
Sorry
reverendleo
08-10-2005, 08:41 PM
Appreciate it sir.
I'm using office 2003, and I'll keep looking for a way to add the COM wrapper.
Thanks!
Roelf
08-11-2005, 10:31 AM
Does dreamweaver use code-behind files? Or does it put the asp.net serverside code in the aspx page itself?
I have tried a client application with the imports statement, so if DW uses code behind, it should go there
reverendleo
08-11-2005, 05:30 PM
Best to my knowledge, all the server-side code is still on the .aspx page itself. Since this is an inter-office application, I'm not to worried about concealing the behind-the-scenes code.
Also, when I add the Imports..... statement below all the <%@ import Namespace....%>, it treats it like text that belongs on the page itself (visible to the page user).
I thought surely there's a way to do this, since it seems relatively simple to do with Visual Studio.
Thanks again sir!
Starlight
08-22-2005, 01:24 PM
Hi reverendleo,
Are you compiling your code as a dll file? I have developed a project at work using dreamweaver with asp.net and vb.net. You will need to put the dll file of the Word COM object in your compile command prompt. Example:
vbc /r:system.dll /r:system.data.dll /t:library /out:..\bin\Login.dll ..\Authenticate\Login.vb
You might need to down load the Imports Microsoft.Office.Interop dll from miscrosoft if it only comes with visual studio and place it in the bin directory.
My next project at work will be involved in using MS word with my .net pages. So I'm looking for similar solutions. Let me know how you get on.
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.