我正在尝试将一个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我检查了这个错误是一个“文件已经存在”的错误,但是这是错误的。当程序开始运行时,目标文件绝对不存在。
发布于 2014-10-20 14:21:00
将扩展更改为
string path = "C:\\elixir.html"; 至
string path = "C:\\elixir.htm";修好了。
https://stackoverflow.com/questions/26363784
复制相似问题