Spire.Doc for .NET (337)
Children categories
Hyperlinks can point to files, emails, websites, imagers or video when readers click on it. Hyperlinks are widely used in word document for it is very convenient to direct readers to related, useful content. By using Spire.Doc, developers can add hyperlinks, finding hyperlinks and modify hyperlinks. This article will show you how to find all the existing hyperlinks in a word document in C#.
Download and install Spire.Doc for .NET and then add Spire.Doc.dll as reference in the downloaded Bin folder though the below path: "..\Spire.Doc\Bin\NET4.0\ Spire.Doc.dll". Here comes to the details of how to finding hyperlinks in C#.
Firstly, view the word document which contains many hyperlinks:

Please check the code of how to find all the hyperlinks in word document:
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Collections.Generic;
using System.Drawing;
namespace FindHyperlink
{
class Program
{
static void Main(string[] args)
{
Document doc = new Document();
doc.LoadFromFile("Spire.docx");
List hyperlinks = new List();
foreach (Section section in doc.Sections)
{
foreach (DocumentObject sec in section.Body.ChildObjects)
{
if (sec.DocumentObjectType == DocumentObjectType.Paragraph)
{
foreach (DocumentObject para in (sec as Paragraph).ChildObjects)
{
if (para.DocumentObjectType == DocumentObjectType.Field)
{
Field field = para as Field;
if (field.Type == FieldType.FieldHyperlink)
{
hyperlinks.Add(field);
}
}
}
}
}
}
}
The effective screenshot of the finding hyperlinks:

In Word document, users can add new page break or remove existing page breaks. This sample shows how to remove page breaks from the word document by using Spire.Doc. Spire.Doc supports to remove the page breaks from the word document from the format of .docx, .doc, and RTF etc.
Firstly make sure Spire.Doc for .NET has been installed correctly and then add Spire.Doc.dll as reference in the downloaded Bin folder though the below path: ".. \Spire.Doc\Bin\NET4.0\ Spire.Doc.dll". Here comes to the details of how to remove page breaks in C#.
//Create a new word document and load from the file.
Document document = new Document();
document.LoadFromFile("sample.docx");
// Traverse every paragraph of the first section of the document
for (int j = 0; j < document.Sections[0].Paragraphs.Count; j++)
{
Paragraph p = document.Sections[0].Paragraphs[j];
// Traverse every child object of a paragraph
for (int i = 0; i < p.ChildObjects.Count; i++)
{
DocumentObject obj = p.ChildObjects[i];
//Find the page break object
if (obj.DocumentObjectType == DocumentObjectType.Break)
{
Break b = obj as Break;
// Remove the page break object from paragraph
p.ChildObjects.Remove(b);
//save the document to file.
document.SaveToFile("result.docx");
Please check the effective screenshot:

Full codes:
using Spire.Doc;
using Spire.Doc.Documents;
namespace RemovePageBreak
{
class Program
{
static void Main(string[] args)
{
Document document = new Document();
document.LoadFromFile("sample.docx", FileFormat.Docx);
for (int j = 0; j < document.Sections[0].Paragraphs.Count; j++)
{
Paragraph p = document.Sections[0].Paragraphs[j];
for (int i = 0; i < p.ChildObjects.Count; i++)
{
DocumentObject obj = p.ChildObjects[i];
if (obj.DocumentObjectType == DocumentObjectType.Break)
{
Break b = obj as Break;
p.ChildObjects.Remove(b);
}
}
}
document.SaveToFile("result.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("result.docx");
}
}
}
Superscripts or subscripts are characters positioned slightly above or below the normal line of text. They are commonly used in scientific formulas such as mathematical equations or chemical expressions. If you are creating a document containing scientific formulas, you most likely need to insert superscripts or subscripts. In this article, we will demonstrate how to insert superscripts and subscripts into Word in C# and VB.NET using Spire.Doc for .NET library.
Install Spire.Doc for .NET
To begin with, you need to add the DLL files included in the Spire.Doc for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.Doc
Insert Superscripts and Subscripts into Word using C# and VB.NET
The following are the main steps to insert a superscript or subscript into a Word document using Spire.Doc for .NET:
- Create a Document instance.
- Load a Word document using Document.LoadFromFile() method.
- Get the specific section through Document.Sections[sectionIndex] property.
- Add a paragraph to the section using Section.AddParagraph() method.
- Add normal text to the paragraph using Paragraph.AppendText() method.
- Add superscript or subscript text to the paragraph using Paragraph.AppendText() method.
- Apply superscript or subscript formatting to the superscript or subscript text through TextRange.CharacterFormat.SubSuperScript property.
- Save the result document using Document.SaveToFile() method.
- C#
- VB.NET
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace InsertSuperscriptAndSubscript
{
class Program
{
static void Main(string[] args)
{
//Create a Document instance
Document document = new Document();
//Load a Word document
document.LoadFromFile("Sample.docx");
//Get the first section
Section section = document.Sections[0];
//Add a paragraph to the section
Paragraph paragraph = section.AddParagraph();
//Add normal text to the paragraph
paragraph.AppendText("E = mc");
//Add superscript text to the paragraph
TextRange superscriptText = paragraph.AppendText("2");
//Apply superscript formatting to the superscript text
superscriptText.CharacterFormat.SubSuperScript = SubSuperScript.SuperScript;
//Start a new line
paragraph.AppendBreak(BreakType.LineBreak);
//Add normal text to the paragraph
paragraph.AppendText("H");
//Add subscript text to the paragraph
TextRange subscriptText = paragraph.AppendText("2");
//Apply subscript formatting to the subscript text
subscriptText.CharacterFormat.SubSuperScript = SubSuperScript.SubScript;
//Add normal text to the paragraph
paragraph.AppendText("O");
//Set font size for the text in the paragraph
foreach (var item in paragraph.Items)
{
if (item is TextRange)
{
TextRange textRange = item as TextRange;
textRange.CharacterFormat.FontSize = 36f;
}
}
//Save the result document
document.SaveToFile("InsertSuperscriptAndSubscript.docx", FileFormat.Docx2013);
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.