OneNoteConversionTool.OutputGenerator.OneNoteGenerator.CreateTableOfContentPage C# (CSharp) Method

CreateTableOfContentPage() public method

Generates a Table of Content Page of all the pages underneath the given section Also sets the Table of Content Page to be the first page in the given section
public CreateTableOfContentPage ( string sectionId, string tocPageTitle = "Table of Contents" ) : string
sectionId string
tocPageTitle string
return string
		public string CreateTableOfContentPage(string sectionId, string tocPageTitle = "Table of Contents")
		{
			string retVal = CreatePage(tocPageTitle, sectionId);

			var sectionHierarchy = GetChildrenScopeHierarchy(sectionId);

			XDocument xdoc = XDocument.Parse(sectionHierarchy);
			XNamespace xNs = xdoc.Root.Name.Namespace;
			var sectionElement = xdoc.Elements(xNs + "Section")
				.Single(x => x.Attribute("ID").Value.Equals(sectionId));

			var tocContent = string.Empty;

			var pageElements = sectionElement.Elements(xNs + "Page");

			//Iterate through the sections and get hyperlinks for them to be put into the new page.
			foreach (var pageElement in pageElements)
			{
				var pageId = pageElement.Attribute("ID").Value;

				//Don't add a link to the ToC page itself
				if (pageId != retVal)
				{
					var pageTitle = pageElement.Attribute("name").Value;
					pageTitle = Encoding.Default.GetString(Encoding.UTF8.GetBytes(pageTitle));
					string hyperLink;

					_mApp.GetHyperlinkToObject(pageId, string.Empty, out hyperLink);

					var pageLevel = int.Parse(pageElement.Attribute("pageLevel").Value);

					while (pageLevel > 1)
					{
						tocContent += "\t";
						--pageLevel;
					}

					tocContent += string.Format("<a href=\"{0}\">{1}</a>", hyperLink, pageTitle) + "\n\n";
				}
			}

			AddPageContent(retVal, tocContent);

			//Move the ToC page to the first page
			SetAsFirstPage(retVal, sectionId);

			return retVal;
		}
		#endregion

Usage Example

		/// <summary>
		/// Helper method to include the common code between the trainer and the student create notebook when converting 
		/// Power Point files that doesn't have sections
		/// </summary>
		/// <param name="pptOpenXml"></param>
		/// <param name="imgsPath"></param>
		/// <param name="note"></param>
		/// <param name="sectionId"></param>
		/// <param name="isTrainer"></param>
		private void ConvertPowerPointWithoutSectionsToOneNote(PowerPointOpenXml pptOpenXml, string imgsPath, OneNoteGenerator note,
			string sectionId, bool isTrainer)
		{
			for (var i = 1; i <= pptOpenXml.NumberOfSlides(); i++)
			{
				string pageId;
				if (isTrainer)
				{
					pageId = InsertPowerPointSlideInOneNote(i, pptOpenXml, imgsPath, note, sectionId, 
						true, StudentNotesTitle, true, TrainerNotesTitle);
				}
				else
				{
					pageId = InsertPowerPointSlideInOneNote(i, pptOpenXml, imgsPath, note, sectionId, 
						true, StudentNotesTitle, false);
				}
				if (!pageId.Equals(String.Empty))
				{
					note.SetShowDate(pageId, false);
					note.SetShowTime(pageId, false);
				}
			}
			string tocPageId = note.CreateTableOfContentPage(sectionId);
			note.SetShowDate(tocPageId, false);
			note.SetShowTime(tocPageId, false);
		}
All Usage Examples Of OneNoteConversionTool.OutputGenerator.OneNoteGenerator::CreateTableOfContentPage