首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当将COMException转换为OneNote时(但它适用于OneNote)

当将COMException转换为OneNote时(但它适用于OneNote)
EN

Stack Overflow用户
提问于 2014-10-14 14:49:02
回答 1查看 657关注 0票数 2

我正在尝试将一个OneNote部分转换为HTML,并不断地遇到一个持久错误。这很奇怪,因为如果我转换为PDF,相同的代码也能工作。我很感谢你帮我这个忙。

代码语言:javascript
复制
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。

下面是异常消息

代码语言:javascript
复制
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.Office.Interop.OneNote.dll
Exception from HRESULT: 0x8004201A

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-20 14:21:00

将扩展更改为

代码语言:javascript
复制
string path = "C:\\elixir.html"; 

代码语言:javascript
复制
string path = "C:\\elixir.htm";

修好了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26363784

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档