sharepoint - Convert docx to pdf with Word Automation Services -


with of http://msdn.microsoft.com/en-us/library/ff742315.aspx tried doing conversion docx pdf on sharepoint ... 1) created cs file on sharepoint server ... 2) compiled a bat file console exe 3) exe runs gives exception system.nullreferenceexception: object reference not set instance of object.

the files exist , editable @ \mysrv\sites\casedocs\documents\elfdev\10080003 , @ https:\mysrv\sites\casedocs\documents\elfdev\10080003, latter no cert error.

1) cs file ...

using system ;  using system.collections.generic ;  using system.linq ;  using system.text ;  using microsoft.sharepoint ;  using microsoft.office.word.server.conversions ;  class program {   static void main( string[] args )   {  string siteurl = "https://mysrv" ;   string wordautomationservicesname = "word automation services" ;   string source = siteurl + "/sites/casedocs/documents/elfdev/10080003/jk1.docx" ;   string target = siteurl + "/sites/casedocs/documents/elfdev/10080003/jk1.pdf" ;   using( spsite spsite = new spsite(siteurl) )   {    conversionjob job = new conversionjob(wordautomationservicesname ) ;     job.usertoken = spsite.usertoken ;     job.settings.updatefields = true ;     job.settings.outputformat = saveformat.pdf ;        // system.null reference exception on next line ...    job.addfile( source ,  target   )  ;   }   } } 

2) compiler bat file ...

csc /out:d2p.exe /target:exe d2pmain.cs /r:"c:\program files\common files\microsoft shared\web server extensions\14\isapi\microsoft.sharepoint.dll" /r:"c:\program files\common files\microsoft shared\web server extensions\14\isapi\microsoft.office.word.server.dll" 

3. full exception ...

unhandled exception: system.nullreferenceexception: object reference not set instance of object.    @ microsoft.office.word.server.folderiterator.checkinputfile(splistitem item )    @ microsoft.office.word.server.folderiterator.checksingleitem(spfile inputfile, spfile outputfile)    @ microsoft.office.word.server.conversions.conversionjob.addfilecore(string inputfilename, string outputfilename)    @ microsoft.office.word.server.conversions.conversionjob.addfile(string inputfile, string outputfile)   @ program.main(string[] args) 

it looks cannot see input file, a) \mysrv\sites\casedocs\documents\elfdev\10080003\jk1.docx open file in word 2010 , b) https://mysrv/sites/casedocs/documents/elfdev/10080003/jk1.docx opens file in word 2010

the problem when running within console application, , not have http context when using server version of microsoft.sharepoint.dll.

the code blows because expecting have http content in microsoft.sharepoint.spcontext variable.

in order code work, must run within sharepoint iis web server.

convert code class, compile sharepoint feature , solution package (.wsp) , deploy sharepoint farm. code work, because microsoft.sharepoint.spcontent populated , won't null.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -