Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将OneNote转换为HTML时的COMException(但适用于PDF)_C#_Office Interop_Comexception_Onenote - Fatal编程技术网

C# 将OneNote转换为HTML时的COMException(但适用于PDF)

C# 将OneNote转换为HTML时的COMException(但适用于PDF),c#,office-interop,comexception,onenote,C#,Office Interop,Comexception,Onenote,我正在尝试将OneNote分区转换为HTML,并一直运行到持续错误。这很奇怪,因为如果我转换成PDF,同样的代码也能工作。我很感激你能帮我做这件事 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Xml.Linq; using OneNote = Microsoft.Office.Interop.OneNote;

我正在尝试将OneNote分区转换为HTML,并一直运行到持续错误。这很奇怪,因为如果我转换成PDF,同样的代码也能工作。我很感激你能帮我做这件事

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Linq;
using OneNote = Microsoft.Office.Interop.OneNote;
using Office = Microsoft.Office.Core;

namespace trial
{
    class Class1
    {
        [STAThread]
        static int Main(string[] args)
        {
            String strXML;
            OneNote.Application onApplication = new OneNote.Application();
            onApplication.GetHierarchy(null,OneNote.HierarchyScope.hsPages, out strXML);

            XDocument doc = XDocument.Parse(strXML);
            XNamespace ns = doc.Root.Name.Namespace;

            foreach (var sectionNode in from node in doc.Descendants(ns+"Section") select node)
            {
                string id = sectionNode.Attribute("ID").Value;
                string path = "C:\\elixir.html";

                if (id == "some specific ID")
                {
                    //confirmed that it reaches this point

                    try
                    {
                        onApplication.Publish(id, path, OneNote.PublishFormat.pfHTML, ""); //PDF conversion Works! But HTML doesn't.
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                    }
                }
            }
            return 0;
        }
    }
}
这是我的推荐信。所有“嵌入互操作类型”设置都已设置为False。

下面是异常消息

A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.Office.Interop.OneNote.dll
Exception from HRESULT: 0x8004201A

我检查了这个错误是否是“文件已经存在”错误,但这是错误的。当程序开始运行时,目标文件肯定不存在。

将扩展名从

string path = "C:\\elixir.html"; 


已修复。

现在它也不再适用于pdf…非常感谢!我只是有同样的问题,没有选择从应用程序内部导出为HTML。
string path = "C:\\elixir.htm";