Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi i create post in the IIS Forum but they Can't resolve it

i in my project use of this code in button :

Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();

var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "New" + ".docx");

object fileName = path;
object readOnly = false;
object startIndex = 0;
object isVisible = true;
object missing = System.Reflection.Missing.Value;

WordApp.Visible = true;

Microsoft.Office.Interop.Word.Document aDoc = WordApp.Documents.Add();

i in visual studio when click on button,to be open word office but when i published on iis7 ,when i click on button ,don't open word office

please help me
Posted
Comments
Dylan Morley 14-Nov-11 4:09am    
Your code is running on a web server. When you are automating office, it's happening *on the server*. When you hit a line of code like 'WordApp.Visible = true;', that's never going to make it visible to the user in their web browser.

The reason it works in visual studio is because you're running it on your computer, where you are the server & the client - this is not something that will work in a deployed solution

You need to rethink how you are going to achieve this.

1 solution

For starters, office automation on a web server really isn't recommended.

http://support.microsoft.com/kb/257757[^]

Is Office correcrly installed on the web server? Does the account running the web process have permissions to all the relevant locations. Any messages in event viewer?

Why not try wrapping your statement in a try-catch block, and then log the Exception to a file.

C#
try
{
    Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();
 
    var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "New" + ".docx");
 
    object fileName = path;
    object readOnly = false;
    object startIndex = 0;
    object isVisible = true;
    object missing = System.Reflection.Missing.Value;
 
    // WHY make an application visible on the server?????!
    WordApp.Visible = true;
 
    Microsoft.Office.Interop.Word.Document aDoc = WordApp.Documents.Add();
}
catch (Exception ex)
{
    // However you log errors
    MyLogger.Log(ex.Message);
}


But really, you shouldn't be doing this. You do understand this is happening on the server, right? It's not going to show anything on the client.
 
Share this answer
 
Comments
Dylan Morley 14-Nov-11 4:03am    
Moved from OP:

thanks for your answer
i try it
and i try this code :
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();
Response.Write("1");
Microsoft.Office.Interop.Word.Document aDoc = WordApp.Documents.Add();
Response.Write("2");
WordApp.Visible = true;
Response.Write("3");

and when i runs on server write 1 & 2 & 3
but just don't open office

i need open office that user can create a document or open a document and edit it
please help me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900