Word无法在RIA服务中打开文档 [英] Word fails to open document in RIA services
问题描述
我正在开发RIA服务应用程序,其中一项要求是从服务器下载文档.这个想法是,客户端执行一个调用操作,该操作在服务器上打开一个word文档,并向其中填充一些数据(例如mailmerge,但使用书签),将其转换为pdf,然后将其作为字节数组发送回去.使用附带的asp.net开发服务器在VS2010中运行时,此方法非常有效.问题是,一旦将其部署到Web服务器,它就会失败.通过添加日志记录,我发现在打开文档时它失败了.它创建了word.application对象,但是在打开文档时失败.它没有错误,但是oDoc对象什么也没有.
代码
I am developing a RIA services application and one of the requirments is to download documents from the server. The idea is that the client executes an invoke operation that opens a word document on the server, populates it with some data (like a mailmerge but using bookmarks), converts it to a pdf and sends it back as a byte array. when running through VS2010 using the asp.net development server included this works perfectly. The problem is that as soon as it is deployed to a webserver it fails. By adding logging i have found that it fails at the point of opening the document. It creates the word.application object but this fails at opening the document. It gives no errors but the oDoc object is nothing.
Code
Dim oWord As Word.Application
Dim oDoc As Word.Document
CRBEntitiesService.mylogger.AddInformation("About to Create Word Application")
oWord = New Word.Application
If oWord Is Nothing Then
CRBEntitiesService.mylogger.AddError("Word Application Failed")
Else
CRBEntitiesService.mylogger.AddInformation("Word Application Created")
End If
Dim [readOnly] As Object = False
Dim isVisible As Object = False
Dim missing As Object = System.Reflection.Missing.Value
oWord.Visible = False
Select Case DiscToProc.Recruiter.SectorID
Case Is = 1
CRBEntitiesService.mylogger.AddInformation("About to Open Word Document: " & My.Computer.FileSystem.CombinePath(My.Settings.LettersFolder, My.Settings.DeclarationMode1))
Try
oDoc = oWord.Documents.Open(My.Computer.FileSystem.CombinePath(My.Settings.LettersFolder, My.Settings.DeclarationMode1), missing,
[readOnly], missing, missing, missing, missing, missing, missing, missing, missing, isVisible)
If oDoc Is Nothing Then
CRBEntitiesService.mylogger.AddInformation("Word Document Failed")
Else
CRBEntitiesService.mylogger.AddInformation("Word Document Opened")
End If
Catch ex As Exception
CRBEntitiesService.mylogger.AddError(ex.Message & vbCrLf & ex.InnerException.Message)
End Try
就像我说的那样,没有错误只是不会做这项工作,而是可以在开发服务器上正常工作.
As i said, No errors just wont do the job but works fine through the development server.
推荐答案
打开现有MS Word文档的正确(且足够)的命令是:
The correct (and sufficient) command to open existing MS Word document is:
oDoc = oWord.Documents.Open(sFileName)
其中sFileName
是文档的完整路径,如下所示:C:\mydoc.doc
但是在检查代码值之前:
where sFileName
is the full path of document, like this: C:\mydoc.doc
But before check the value of your code:
sFileName = My.Computer.FileSystem.CombinePath(My.Settings.LettersFolder, My.Settings.DeclarationMode1)
MsgBox (sFileName)
并打开文档后:
And after opening the document:
oWord.Visible = True
这篇关于Word无法在RIA服务中打开文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!