2013-07-09 77 views
2

我只是想使用我的web應用程序從Word文件中讀取文本。它在我的本地系統中運行良好,並且在我將其託管在服務器中之後,word文件不會打開,並且其拋出的null異常。在C中打開Word文件#

這是我過得怎麼樣,

Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application(); 
Microsoft.Office.Interop.Word.Document WordDoc = new Microsoft.Office.Interop.Word.Document(); 
object DocNoParam = Type.Missing; 
object DocReadOnly = false; 
object DocVisible = false; 

WordDoc = WordApp.Documents.Open(BO.Misc.Settings.AttachementPathRelative + fileName, 
              ref DocNoParam, 
              ref DocReadOnly, 
              ref DocNoParam, 
              ref DocNoParam, 
              ref DocNoParam, 
              ref DocNoParam, 
              ref DocNoParam, 
              ref DocNoParam, 
              ref DocNoParam, 
              ref DocVisible, 
              ref DocNoParam, 
              ref DocNoParam, 
              ref DocNoParam, 
              ref DocNoParam, 
              ref DocNoParam); 

     WordDoc.Activate();    

我已經安裝在服務器的辦公室,我已經給互操作的參考我的Web應用程序也是如此。我不知道爲什麼我得到錯誤。有人可以幫我從這裏出去嗎。提前致謝。

我得到錯誤WordDoc.Activate(),問題是我沒有在我的系統中安裝Visual Studio,所以我無法調試它。它扔我一個異常說System.NullReferenceException: Object reference not set to an instance of an object.

和堆棧跟蹤是[NullReferenceException: Object reference not set to an instance of an object.] Profile_CreateProfile.btnResumeUpload_Click(Object sender, EventArgs e) in d:\Apps\App1\Employee\AddEmployee.aspx.cs:411 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +153 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3690

+3

發佈異常詳細信息:消息,類型,堆棧跟蹤,拋出異常的代碼行。 –

+1

這不是解決你的問題,但我認爲你應該使用'Path.Combine(...)'而不是'BO.Misc.Settings.AttachementPathRelative + fileName'' System.IO.Path.Combine(BO.Misc.Settings .AttachementPathRelative,fileName)'。 'Path.Combine(..)'更健壯。 – mortb

+0

@defaultlocale我已更新我的問題,你現在可以檢查嗎? – shanish

回答

2

它不建議您使用互操作模式在服務器環境(如ASP應用程序)爲「辦公室可能會出現不穩定的行爲和/或死鎖時,辦公室在這個環境中運行。「 (Read this for more details)

您應該使用OpenXML在服務器上創建Word文檔。

+0

謝謝瑞恩,我會檢查它。 – shanish