如何在C#中删除OneNote页面?

如何在C#中删除OneNote页面?,c#,onenote,C#,Onenote,我正在使用C#中的OneNote interop尝试使用以下代码块删除页面: static string GetObjectId(string parentId, HierarchyScope scope, string objectName) { string xml; onenote.GetHierarchy(parentId, scope, out xml); var doc = XDocument.Parse(xml); var nodeName = "

我正在使用C#中的OneNote interop尝试使用以下代码块删除页面:

static string GetObjectId(string parentId, HierarchyScope scope, string objectName)
{
    string xml;
    onenote.GetHierarchy(parentId, scope, out xml);

    var doc = XDocument.Parse(xml);
    var nodeName = "";

    switch (scope)
    {
        case (HierarchyScope.hsNotebooks): nodeName = "Notebook"; break;
        case (HierarchyScope.hsPages): nodeName = "Page"; break;
        case (HierarchyScope.hsSections): nodeName = "Section"; break;
        default:
            return null;
    }

    var node = doc.Descendants(ns + nodeName)
        .Where(n => n.Attribute("name").Value == objectName)
        .FirstOrDefault();

    return node.Attribute("ID").Value;
}

static string DeletePage(string sectionId, string pageId, string pageName)
{
    var pageId = GetObjectId(sectionId, HierarchyScope.hsPages, pageName);
    onenote.DeleteHierarchy(pageId, DateTime.MinValue, true);
}
但每次我打开OneNote时,页面都会保留下来

我在下一页读到,这是我应该使用的方法,但我似乎运气不太好:


有人能告诉我如何使用C#中的OneNote interop删除OneNote中的页面吗?

这是一个老问题,但由于没有答案。。。我发现只需按如下方式调用函数:

onenote.DeleteHierarchy(pageId)
工作并将导致文件被发送到回收站。如果要完全删除页面,请执行以下操作:

onenote.DeleteHierarchy(pageId, deletePermanently:true)
使用dateExpectedLastModified参数有点棘手。
Per MSDN–(可选)您认为要删除的对象上次修改的日期和时间。如果为此参数传递非零值,仅当传递的值与上次修改对象的实际日期和时间匹配时,OneNote才会继续更新。传递此参数的值有助于防止意外覆盖用户自上次修改对象以来所做的编辑