none
Calling MS Word from a windows service or scheduled task RRS feed

  • Question

  • I'm doing some SharePoint integration. I have a C# application which I can run to obtain a document from SharePoint, convert it using Word to PDF, then upload it into another SharePoint library.

    When I create a scheduled task to call my application the conversion is not performed.

    When I drop the code into a service the conversion is not performed.

    The code which performs the conversion is a generic piece of VBS, called using "cscript WordToPDF filename", which I include here:

    Function WordToPDF( sDocFile )
      Dim fso ' As FileSystemObject
      Dim wdo ' As Word.Application
      Dim wdoc ' As Word.Document
      Dim wdocs ' As Word.Documents
      Dim sPrevPrinter ' As String
      Dim sPDFFile ' As String
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set wdo = CreateObject("Word.Application")
      Set wdocs = wdo.Documents
      sDocFile = fso.GetAbsolutePathName(sDocFile)
      sFolder = fso.GetParentFolderName(sDocFile)
      sPDFFile = sFolder + "\" + fso.GetBaseName(sDocFile) + ".pdf"
      wdo.WordBasic.DisableAutoMacros
      Set wdoc = wdocs.Open(sDocFile)
      wdoc.SaveAs sPDFFile, wdFormatPDF
      wdoc.Close WdDoNotSaveChanges
      wdo.Quit WdDoNotSaveChanges
      Set wdo = Nothing
      Set fso = Nothing
    End Function
    
    Now, I know that the code works when run as a user. What is the issue with calling it as a task or service? What is the work around?

    Thanks.

    Monday, December 5, 2011 10:10 AM

Answers