Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Path for my Word document Not found

Status
Not open for further replies.

Gixonita

IS-IT--Management
Oct 17, 2005
103
US
Hi all,

I'm trying to open a word document using:

Note: Replace $$$$$ in the code window with all these

"Document\Test1.doc";
"Document\\Test1.doc";
"@"
Code:
Word.Application	WordApplication = new Word.Application ();
	
			object FileName		= $$$$$
			object ReadOnly		= true;
			object IsVisible	= true;
			object MissingValue	= Type.Missing;

			Word.Document	WordDocument	= WordApplication.Documents.Open (ref FileName, ref MissingValue,
												  ref ReadOnly, ref MissingValue, ref MissingValue, ref MissingValue, 
												  ref MissingValue, ref MissingValue, ref MissingValue, ref MissingValue, 
												  ref MissingValue, ref IsVisible, ref MissingValue, ref MissingValue, 
												  ref MissingValue, ref MissingValue);

			WordApplication.Visible = true;

And the result is always the same, I get the message:

System.Runtime.InteropServices.COMException: The document name or path is not valid. Try one or more of the following: * Check the path to make sure it was typed correctly. * On the File menu, click Open. Search for the file using this dialog box. (
I'm using visual studio 2003 with c#. The file is definetly in the directory, the folder is added to the project, and I have NO idea why it will not find it.

Anyone has gone through this?

Thanks

Luis Torres
 
Disregard this first problem, I solved it by setting the complete path to the file starting with "C:\\.....".

Now I have a new problem, with the code:

Code:
private void btnOpenDocument_Click(object sender, System.EventArgs e)
		{
			Word.Application	WordApplication = new Word.Application ();
	
			object FileName		= "C:\\JudgeDocuments\\Test1.doc";
			object ReadOnly		= true;
			object IsVisible	= true;
			object MissingValue	= Type.Missing;

			WordApplication.Visible = true;
			WordApplication.Activate ();

			Word.Document	WordDocument	= WordApplication.Documents.Open (ref FileName, ref MissingValue,
				ref ReadOnly, ref MissingValue, ref MissingValue, ref MissingValue, 
				ref MissingValue, ref MissingValue, ref MissingValue, ref MissingValue, 
				ref MissingValue, ref IsVisible, ref MissingValue, ref MissingValue, 
				ref MissingValue, ref MissingValue);

			WordDocument.Activate ();			
		}

I get the error message:

Exception Details: System.Runtime.InteropServices.COMException: Cannot activate application

Has anyone seen this?

Thanks

Luis Torres
 
Have you given DCOM launch and execute permissions for ASPNET account to the word application?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Yes, for:

ASP.NET Machine Account (LUISTORRES\ASPNET) I set Allow on
-Local Launch
-Remote Launch
-Local Activation
-Remote Activation
 
Hmmm...what happens if you remove the "WordDocument.Activate ();" lines?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Same error

My project references to:

- Microsoft.Office.Core
- System
- System.Data
- System.Drawing
- System.Web
- System.XML
- VBIDE
- Word

Does this seem right to you? The only one that I don't get is the VBIDE
 
Are you using the Word object from the Interop class?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
This is all that I'm using:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Runtime.InteropServices;
using Word = Microsoft.Office.Interop.Word;
 
using Word = Microsoft.Office.Interop.Word;
Yes, the above line shows you are using it correctly (as far as I know anyway). I'm pretty sure that it's either:

1) The ASPNET account can't launch it because of a permissions issue
2) It can access it but can't display it (i.e. when you set the Visible property or when you call the Activate method).

However, we've gone over these two issues and it doesn't seem to have made a difference. Hopefully someone else will have some other ideas that we haven't tried.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks for your help, I've been doing a lot of research and at the moment everything has turned out useless.

I was checking the process with task manager and I can see the process starting but nothing is displayed on screen. (taking out the Activate (), just leaving the Visible = true)

I'll keep investigating and post the solution if I come up with one.
 
For anyone interested.....

The problem is definetly not solved, but I just used a work around. Instead of trying to control Word I just redirected the page giving the file in the URL, that forces the browser to open word and load the document.

I know it's "cheap" but for now it gets the job done.
 
I don't understand. Were you actually trying to just open the word document on the client's machine?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
No, I'm also trying to manipulate it, but for now the user is "happy" being able to see it.
 
Oh ok


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top