Skip to content

Commit 6aff73c

Browse files
committed
Add experimental rename method
1 parent baf9d6a commit 6aff73c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Odotocodot.OneNote.Linq/OneNoteParser.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,37 @@ public static string GetPageContent(IApplication oneNote, OneNotePage page)
340340
public static void CloseNotebook(IApplication oneNote, OneNoteNotebook notebook) => oneNote.CloseNotebook(notebook.ID);
341341

342342
//TODO: Rename item
343+
internal static void RenameItem(IApplication oneNote, IOneNoteItem item, string newName)
344+
{
345+
if (item.IsInRecycleBin())
346+
{
347+
throw new ArgumentException("Cannot rename unique items, such as recycle bin.");
348+
}
349+
oneNote.GetHierarchy(null, HierarchyScope.hsPages, out string xml);
350+
var doc = XDocument.Parse(xml);
351+
var element = doc.Descendants()
352+
.FirstOrDefault(e => (string)e.Attribute("ID") == item.ID);
353+
if (element != null)
354+
{
355+
element.Attribute("name").SetValue(newName);
356+
oneNote.UpdateHierarchy(doc.ToString());
357+
switch (item)
358+
{
359+
case OneNoteNotebook nb:
360+
nb.Name = newName;
361+
break;
362+
case OneNoteSectionGroup sg:
363+
sg.Name = newName;
364+
break;
365+
case OneNoteSection s:
366+
s.Name = newName;
367+
break;
368+
case OneNotePage p:
369+
p.Name = newName;
370+
break;
371+
}
372+
}
373+
}
343374

344375
#region Creating New OneNote Items
345376
//TODO: change to return ID

0 commit comments

Comments
 (0)