Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
528 views
in Technique[技术] by (71.8m points)

c# - Opening Word Document on Client Side from Asp.net Application

We need to open a word document which is located on a server on the clients machine using Microsoft Word. The solution is working locally however when deployed on server then only thing that happens is that the winword.exe is started on the server. Is this possible to do using interop or javascript?

this is the code till now

Microsoft.Office.Interop.Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();

object file = FilePath + FileName;
lblError.Text = lblError.Text + file.ToString(); 
object readOnly = false;
object objTrue = true;
object missing = System.Reflection.Missing.Value;
object emptyData = string.Empty;
wordApp.Visible = true;
Microsoft.Office.Interop.Word.Document aDoc                         =
wordApp.Documents.Open(ref file,
         ref missing, ref readOnly,
         ref missing, ref missing, ref missing,
         ref missing, ref missing, ref missing,
         ref missing, ref missing, ref objTrue);

aDoc.Activate();
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have to keep in mind that the client and server are running on two different machines. The server can't start a program running on the client machine.

Also, FYI, never use Office Automation from an ASP.NET application. Those APIs were designed for use in a desktop application. They won't work properly, are unsupported, and may even violate your Office license.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...