2011-09-12 2 views
3

웹 서비스를 작성 중이며 .docx 또는 .doc을 .xps로 변경하고 싶습니다. 나는 다음과 같은 형식을 .xps로 저를 저장하는 데 도움이 사무실 COM을 사용하고 있습니다 :asp.net 웹 서비스를 사용하는 사무실 2010 COM

 [WebMethod] 
    public string GetDocPreviewUrl(string m_userName, string m_orgFileName) 
    { 
     string m_returnUrl = ""; 

     string m_orgFilePath = _currentDirectory + "\\" + m_userName + "\\" + m_orgFileName; 
     if (File.Exists(m_orgFilePath)) 
     { 
      string m_xpsFilePath = _currentDirectory + "\\" + m_userName + "\\" + 
            Path.GetFileNameWithoutExtension(m_orgFileName) + ".xps"; 

      OfficeToXpsConversionResult m_converstionResult = OfficeToXps.ConvertToXps(m_orgFilePath, ref m_xpsFilePath); 

      m_returnUrl = _baseUrl + m_userName + "/"+ Path.GetFileName(m_xpsFilePath); 
     } 
     return m_returnUrl; 
    } 

     private static OfficeToXpsConversionResult ConvertFromWord(string sourceFilePath, ref string resultFilePath) 
    { 
     object pSourceDocPath = sourceFilePath; 

     string pExportFilePath = string.IsNullOrWhiteSpace(resultFilePath) ? GetTempXpsFilePath() : resultFilePath; 


     Word.Application() wordApplication = new Word.Application(); 

     //wordDocument = wordApplication.Documents.Open(ref pSourceDocPath); 
     dynamic wordDocument = wordApplication.Documents.Add(pSourceDocPath); 

       //return new OfficeToXpsConversionResult(ConversionResult.ErrorUnableToOpenOfficeFile, exc.Message, exc); 

     if (wordDocument != null) 
     { 
      wordDocument.SaveAs(pExportFilePath, WdSaveFormat.wdFormatXPS); 
     } 

     resultFilePath = pExportFilePath; 

     return new OfficeToXpsConversionResult(ConversionResult.OK, pExportFilePath); 
    } 

그러나, 나는 예외를 가지고 내가 웹 메소드에 의해 호출하려고하면

System.Runtime합니다. InteropServices.COMException : 말씀 發生 問題 System.Dynamic.ComRuntimeHelpers.CheckThrowException에서 (INT32의 HRESULT, EXCEPINFO & EXCEPINFO, UINT32 argErr, 문자열 메시지) CallSite.Target (폐쇄, CallSite,하여 ComObject 개체) 에서 System.Dynamic에서. .UpdateDelegates.UpdateAndExecute2 [T0, T1, TRet] (CallSite 사이트, T0 arg0, T (CallSite 사이트, T0 arg0, T1 arg1)에서 에서 DoSProcessService.OfficeToXps. C : \ Users \ Icicle \ Documents \ Fotomax WP7 \ DocProcessService \ DocProcessService \ OfficeHelper \ OfficeToXps.cs의 DocProcessService.OfficeToXps.ConvertToXps (문자열 sourceFilePath, 문자열 & resultFilePath)의 줄 145 줄에서 (문자열 sourceFilePath, 문자열 & resultFilePath) : \ Users \ Icicle \ Documents \ Fotomax WP37 \ DocProcessService \ DocProcessService \ OfficeHelper \ OfficeToXps.cs : DocProcessService.DocDownload.GetDocPreviewUrl (문자열 m_userName, 문자열 m_orgFileName)의 줄에서 C : \ Users \ Icicle \ Documents \ Fotomax WP7 \ DocProcessService \ DocProcessService \ DocDownload.asmx.cs : 줄 90

사무실을 사용하여 xps로 저장하는 코드는 내 WPF 프로젝트에서 잘 작동했습니다. 내 asp.net 4.0 웹 서비스에서 어떻게 사용할 수 있습니까? 감사.

답변