在此http://msdn.microsoft.com/en-us/library/ff742315.aspx的帮助下,我尝试在 sharepoint 上将 docx 转换为 pdf ... 1)我在 sharepoint 服务器上创建了一个 cs 文件。 .. 2) 我用 bat 文件编译到控制台 exe 3) exe 运行但给出异常 System.NullReferenceException: Object reference not set to an instance of an object。
这些文件在 \mysrv\sites\casedocs\Documents\ElfDev\10080003 和 https:\mysrv\sites\casedocs\Documents\ElfDev\10080003 存在并可编辑,后者没有证书错误。
1) Cs 文件...
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)编译器bat文件...
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. 完全例外...
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Office.Word.Server.FolderIterator.CheckInputFile(SPListItem item )
at Microsoft.Office.Word.Server.FolderIterator.CheckSingleItem(SPFile inputFile, SPFile outputFile)
at Microsoft.Office.Word.Server.Conversions.ConversionJob.AddFileCore(String inputFileName, String outputFileName)
at Microsoft.Office.Word.Server.Conversions.ConversionJob.AddFile(String inputFile, String outputFile) at Program.Main(String[] args)
看起来它看不到输入文件,但是 a) \mysrv\sites\casedocs\Documents\ElfDev\10080003\jk1.docx 将在 word 2010 中打开文件和 b) https://mysrv/sites/casedocs/Documents /ElfDev/10080003/jk1.docx在 Word 2010 中打开文件