如何从服务以编程方式打开InfoPath 2007文件?

时间:2022-12-22 02:30:08

I am trying to open an InfoPath 2007 file programmatically from a Windows service, but I get the following error:

我试图从Windows服务以编程方式打开InfoPath 2007文件,但是我收到以下错误:

System.Runtime.InteropServices.COMException (0x80043000): InfoPath cannot open the following file: C:\path\datafile.xml. Not enough storage is available to complete this operation.

System.Runtime.InteropServices.COMException(0x80043000):InfoPath无法打开以下文件:C:\ path \ datafile.xml。没有足够的存储空间来完成此操作。

This file opens correctly in the InfoPath designer. It also runs programmatically as a WinForms application. But when you try to run as a Windows service, it blows up.

此文件在InfoPath设计器中正确打开。它还以编程方式作为WinForms应用程序运行。但是,当您尝试作为Windows服务运行时,它会爆炸。

I have consulted the mighty Google. The two main results that come back are either malformed XML (not the cause, as the form opens correctly manually) or something to do with trying to access a database (which I am not doing).

我咨询了强大的谷歌。返回的两个主要结果是格式错误的XML(不是原因,因为表单手动正确打开)或者尝试访问数据库(我没有做)。

Does anyone know how to do this? Are there permissions I need to set on the service?

有谁知道如何做到这一点?我需要在服务上设置权限吗?

Update:

As per Anders request, here is the code. Note that this may not be the exact code I was working with 6 months ago when I originally posted the question. We have since moved on to using XtraReports, as it seems much easier to work with and has less of these cryptic errors. I would, however, like to resolve this question for anyone else who comes along and may need an answer.

根据Anders的要求,这是代码。请注意,这可能不是我最初发布问题时6个月前使用的确切代码。我们已经转而使用XtraReports,因为它似乎更容易使用,并且具有较少的这些神秘错误。但是,我想为其他任何人提出这个问题,并且可能需要回答。

Microsoft.Office.Interop.InfoPath.Application infoApp = new Microsoft.Office.Interop.InfoPath.Application();
try
{
    Microsoft.Office.Interop.InfoPath.XDocument xDoc = null;
    xDoc = infoApp.XDocuments.Open(fileName, (int)Microsoft.Office.Interop.InfoPath.XdDocumentVersionMode.xdUseExistingVersion);

    xDoc.PrintOut();
    infoApp.XDocuments.Close(0);
}
catch (Exception ex)
{
    //handle error here
}
finally
{
    try
    {
        if (infoApp != null)
            infoApp.Quit(false);
    }
    catch { }
}

1 个解决方案

#1


0  

this worked for us

这对我们有用

#1


0  

this worked for us

这对我们有用