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

RemoveAuthor() public method

Removes the author from any node in the page
public RemoveAuthor ( string pageId ) : void
pageId string
return void
		public void RemoveAuthor(string pageId)
		{
			var doc = GetPageContent(pageId);
			var nodes = doc.SelectNodes("//*[@author or @authorInitials or @lastModifiedBy or @lastModifiedByInitials]", GetNSManager(doc.NameTable));
			
			if (nodes == null)
				return;

			foreach (XmlNode node in nodes)
			{
				if (node.Attributes == null)
					continue;

				if (node.Attributes["author"] != null)
					node.Attributes["author"].Value = String.Empty;
				if (node.Attributes["authorInitials"] != null)
					node.Attributes["authorInitials"].Value = String.Empty;
				if (node.Attributes["lastModifiedBy"] != null)
					node.Attributes["lastModifiedBy"].Value = String.Empty;
				if (node.Attributes["lastModifiedByInitials"] != null)
					node.Attributes["lastModifiedByInitials"].Value = String.Empty;
			}

			// update the page
			_mApp.UpdatePageContent(doc.OuterXml);
		}
		#endregion

Usage Example

		/// <summary>
		/// Inserts a power point slide into a given section in OneNote as a page
		/// </summary>
		/// <param name="slideNumber"></param>
		/// <param name="pptOpenXml"></param>
		/// <param name="imgsPath"></param>
		/// <param name="note"></param>
		/// <param name="sectionId"></param>
		/// <param name="showComments"></param>
		/// <param name="commentsStr"></param>
		/// <param name="showNotes"></param>
		/// <param name="notesStr"></param>
		/// <param name="hiddenSlideNotIncluded"></param>
		/// <returns>the page ID</returns>
		protected string InsertPowerPointSlideInOneNote(int slideNumber, PowerPointOpenXml pptOpenXml, string imgsPath,
			OneNoteGenerator note, string sectionId, bool showComments = true, string commentsStr = "Comments",
			bool showNotes = true, string notesStr = "Notes", bool hiddenSlideNotIncluded = true)
		{
			// skip hidden slides
			if (hiddenSlideNotIncluded && pptOpenXml.IsHiddenSlide(slideNumber))
			{
				return String.Empty;
			}

			// get the image representing the current slide as HTML
			string imgPath = String.Format("{0}\\Slide{1}.png", imgsPath, slideNumber);
			Image img;
			try
			{
				img = Image.FromFile(imgPath);
			}
			catch (FileNotFoundException e)
			{
				Console.WriteLine("Slide {0} was not converted", slideNumber);
                Console.WriteLine(e.Message);
				img = null;
			}

			// insert the image
			string pageTitle = pptOpenXml.GetSlideTitle(slideNumber);
			pageTitle = String.IsNullOrEmpty(pageTitle) ? String.Format("Slide{0}", slideNumber) : pageTitle;
			string pageId = note.CreatePage(pageTitle, sectionId);
			if (img != null)
			{
				note.AddImageToPage(pageId, img);
				img.Dispose();
			}

			// Add comments
			string slideComments = pptOpenXml.GetSlideComments(slideNumber, false);
			if (showComments && !String.IsNullOrEmpty(slideComments))
			{
				note.AppendPageContent(pageId, commentsStr + ": \n\n" + slideComments, (int)note.GetPageWidth(pageId));
			}

			// Add notes
			string slideNotes = pptOpenXml.GetSlideNotes(slideNumber);
			if (showNotes && !String.IsNullOrEmpty(slideNotes))
			{
				note.AppendPageContent(pageId, notesStr + ": \n\n" + slideNotes, (int)note.GetPageWidth(pageId));
			}

			// remove the author
			note.RemoveAuthor(pageId);

			return pageId;
		}