serviço da web asp.net usando o Office 2010 COM
Estou escrevendo um serviço da Web e gostaria de alterar o .docx ou .doc para .xps. Estou usando o office com para me ajudar a salvar no formato .xps da seguinte forma:
[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);
}
No entanto, recebi uma exceção ao tentar chamar pelo método da web:
System.Runtime.InteropServices.COMException: Word em System.Dynamic.ComRuntimeHelpers.CheckThrowException (Int32 hresult, ExcepInfo & excepInfo, UInt32 argErr, String string) em CallSite.Target (Closure, CallSite, ComObject, Object) em System. Dynamic.UpdateDelegates.UpdateAndExecute2 [T0, T1, TRet] (site CallSite, T0 arg0, T1 arg1) em CallSite.Target (Closure, CallSite, Object, Object) em System.Dynamic.UpdateDelegates.UpdateAndExecute2 [T0, T1, TRet] (Site CallSite, T0 arg0, T1 arg1) em DocProcessService.OfficeToXps.ConvertFromWord (String sourceFilePath, String & resultFilePath) em C: \ Users \ Icicle \ Documents \ Fotomax WP7 \ DocProcessService \ DocProcessService \ OfficeHelper \ OfficeToXps.cs: .OfficeToXps.ConvertToXps (String sourceFilePath, String & resultFilePath) em C: \ Users \ Icicle \ Documents \ Fotomax WP7 \ DocProcessService \ DocProcessService \ OfficeHelper \ OfficeToXps.cs: linha 63 em DocProcessService.DocDownload.GetDocPreviewUrl gFileName) em C: \ Usuários \ Sincelo \ Documentos \ Fotomax WP7 \ DocProcessService \ DocProcessService \ DocDownload.asmx.cs: linha 90
O código do uso do office para salvar como xps estava funcionando bem no meu projeto WPF. Como posso usá-lo no meu serviço da web asp.net 4.0? Obrigado