当前位置: 首页>>代码示例>>C#>>正文


C# ApplicationClass.UpdateHierarchy方法代码示例

本文整理汇总了C#中ApplicationClass.UpdateHierarchy方法的典型用法代码示例。如果您正苦于以下问题:C# ApplicationClass.UpdateHierarchy方法的具体用法?C# ApplicationClass.UpdateHierarchy怎么用?C# ApplicationClass.UpdateHierarchy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ApplicationClass的用法示例。


在下文中一共展示了ApplicationClass.UpdateHierarchy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NewItem

        /// <summary>
        /// Creates a new OneNote "thing" -- notebook, section, section group, or page.
        /// </summary>
        /// <param name="path">The path of the new thing to create.</param>
        /// <param name="itemTypeName">The type of thing to create.</param>
        /// <param name="newItemValue">In the notebook creation case, this parameter is the directory in which
        /// the notebook directory will get created.</param>
        protected override void NewItem(string path, string itemTypeName, object newItemValue)
        {
            WriteDebug("In NewItem. Path = " + path);
            string parentPath = SessionState.Path.ParseParent(path, null);
            string childName = SessionState.Path.ParseChildName(path);
            WriteDebug("Parsed path as: Parent = " + parentPath + ", child = " + childName);
            XmlNode parent = getOneNoteNode(parentPath);
            if (parent == null)
            {
                WriteInvalidPathError(parentPath);
                return;
            }

            //
            //  Find out what we're creating. Per guidelines, itemTypeName is case-insensitive,
            //  and it's sufficient for it to be enough characters to disambiguate between the options
            //  in OneNoteTypes.
            //

            List<string> candidates = new List<string>( );
            Microsoft.Office.OneNote.PowerShell.Utilities.GetCandidatesForString(OneNoteTypes, itemTypeName, candidates);
            if (candidates.Count > 1)
            {
                WriteError(new ErrorRecord(
                    new ArgumentException("itemTypeName is ambiguous"),
                    "InvalidArgument",
                    ErrorCategory.InvalidArgument,
                    itemTypeName)
                );
                return;
            }
            if (candidates.Count == 0)
            {
                WriteError(new ErrorRecord(
                    new ArgumentException("itemTypeName not a recognized OneNote type"),
                    "InvalidArgument",
                    ErrorCategory.InvalidArgument,
                    itemTypeName)
                );
                return;
            }
            string selectedType = candidates[0];
            Microsoft.Office.Interop.OneNote.ApplicationClass app = new ApplicationClass( );
            string id;
            switch (selectedType)
            {
                case "Notebook":
                    string notebookPath = SessionState.Path.Combine((string)newItemValue, childName);
                    WriteVerbose("Creating notebook in " + notebookPath);
                    app.OpenHierarchy(notebookPath, "", out id, CreateFileType.cftNotebook);
                    break;

                case "Directory":
                case "Section":
                    if (parent.LocalName != "Notebook")
                    {
                        WriteError(new ErrorRecord(new ArgumentException(path + " is not a valid section path: It is not contained in a notebook."),
                            "InvalidArgument",
                            ErrorCategory.InvalidArgument,
                            path));
                        return;
                    }
                    WriteVerbose("Creating section " + childName +
                        " in notebook ID " + parent.Attributes["ID"].Value);
                    app.OpenHierarchy(childName + ".one",
                        parent.Attributes["ID"].Value,
                        out id, 
                        CreateFileType.cftSection);
                    break;

                case "Page":

                    //
                    //  Creating pages is a bit more work than creating notebooks or sections. I need to build
                    //  up a bit of XML describing the page creation operation.
                    //

                    WriteVerbose("Creating page " + childName);
                    string parentId = parent.Attributes["ID"].Value;
                    OneNoteXml command = new OneNoteXml( );
                    XmlElement section = command.CreateSection(null, parentId);
                    command.Document.AppendChild(section);
                    XmlElement page = command.CreatePage(childName, null);
                    section.AppendChild(page);
                    string xml = command.Document.OuterXml;
                    WriteVerbose(xml);
                    app.UpdateHierarchy(xml);
                    break;
            }
        }
开发者ID:c0ns0le,项目名称:OneNotePowerShellProvider,代码行数:97,代码来源:OneNoteProvider.cs


注:本文中的ApplicationClass.UpdateHierarchy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。