OneNoteConversionTool.OutputGenerator.OneNoteGenerator.AddPageContentAsHtmlBlock C# (CSharp) 메소드

AddPageContentAsHtmlBlock() 공개 메소드

Adds the content as a HTML block.
public AddPageContentAsHtmlBlock ( string pageId, string content, int yPos = 80, int width = 520 ) : void
pageId string Id of the page
content string content to be added
yPos int Starting position of the block
width int Width of the block
리턴 void
		public void AddPageContentAsHtmlBlock(string pageId, string content, int yPos = 80, int width = 520)
		{
			var doc = GetPageContent(pageId);
			var page = doc.SelectSingleNode("//one:Page", GetNSManager(doc.NameTable));
			if (page == null)
				return;

			try
			{
				//If outline doesn't exist, create one
				if (doc.SelectSingleNode("//one:Page/one:Outline", GetNSManager(doc.NameTable)) == null)
				{
					XmlNode childOutline = doc.CreateElement("one:Outline", NS);

					childOutline.InnerText = string.Format(HtmlOutline, yPos, width, content);

					page.AppendChild(childOutline);
					string childContent = Utility.UnescapeXml(childOutline.InnerXml);
					string newPageContent = doc.InnerXml.Replace(childOutline.InnerXml, childContent);

					//Override the content
					_mApp.UpdatePageContent(newPageContent, DateTime.MinValue);
				}
				else
				{
					UpdatePageContent(pageId, content);
				}
			}
			catch (Exception e)
			{
				throw new ApplicationException("Error in AddPageContent: " + e.Message, e);
			}
		}

Usage Example

		/// <summary>
		/// Converts Html file into OneNote Section of Pages
		/// </summary>
		/// <param name="inputFile"></param>
		/// <param name="originalPicFolder"></param>
		/// <param name="auxPicFolder"></param>
		/// <param name="onGenerator"></param>
		/// <param name="sectionId"></param>
		/// <returns></returns>
		protected virtual bool ConvertHtmlToOneNote(string inputFile, string originalPicFolder, string auxPicFolder, OneNoteGenerator onGenerator, string sectionId)
		{
			var retVal = false;
			var htmlContent = string.Empty;

			try
			{
				using (var sr = new StreamReader(inputFile, Encoding.Default))
				{
					htmlContent = sr.ReadToEnd();
				}

				var htmlDoc = new HtmlDocument();
				htmlDoc.LoadHtml(htmlContent);

				//Preserve the HTML surrounding tags
				var content = htmlDoc.DocumentNode;

				var previousPageTitle = string.Empty;

				//store error info
				var errorList = new List<Dictionary<InfoType, string>>();

				foreach (var page in SeparatePages(content))
				{
					if (page != null)
					{
						//Get page title
						var pageTitle = GetPageTitle(page);

						//Create the page
						var pageId = onGenerator.CreatePage(pageTitle, sectionId);

						//error info
						var errorInfo = new Dictionary<InfoType, string>();

						//Add the content of the page
						var pageContent = GeneratePageContent(content, page, originalPicFolder, auxPicFolder, errorInfo);
						onGenerator.AddPageContentAsHtmlBlock(pageId, pageContent);

						//Attempt to do subpage
						if (!pageTitle.Equals(DefaultPageTitle, StringComparison.CurrentCultureIgnoreCase) &&
							pageTitle.Equals(previousPageTitle, StringComparison.CurrentCultureIgnoreCase))
						{
							onGenerator.SetSubPage(sectionId, pageId);
						}

						previousPageTitle = pageTitle;

						if (errorInfo.Count > 0)
						{
							errorInfo.Add(InfoType.Id, pageId);
							errorInfo.Add(InfoType.Title, pageTitle);
							errorList.Add(errorInfo);
						}
					}
				}
				if (errorList.Count > 0)
				{
					CreateErrorPage(onGenerator, sectionId, errorList);
				}

				retVal = true;
			}
			catch (Exception e)
			{
				Console.WriteLine(e.Message);
				retVal = false;
			}

			return retVal;
		}
All Usage Examples Of OneNoteConversionTool.OutputGenerator.OneNoteGenerator::AddPageContentAsHtmlBlock