C#/VB.NET: Insert WordArt in Word

2022-06-24 07:20:00 Written by Koohji

WordArt is a feature in MS Word that allows you to insert colorful and stylish text into your document. Apart from that, it can also bend, stretch, or skew the shape of the text, which is a quick way to make the text stand out with special effects. In this article, you will learn how to programmatically insert WordArt in a Word document using Spire.Doc for .NET.

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 WordArt in Word

The ShapeType enumeration provided by Spire.Doc for .NET defines a variety of WordArt shape types whose names begin with "Text". In order to create a WordArt in Word, you need to initialize an instance of ShapeObject and specify the WordArt type and text content. The detailed steps are as follows:

  • Create a Document instance.
  • Add a section to the document using Document.AddSection() method, and then add a paragraph to the section using Section.AddParagraph() method.
  • Append a shape to the paragraph and specify the shape size and type using Paragraph.AppendShape(float width, float height, ShapeType shapeType) method.
  • Set the position of the shape using ShapeObject.VerticalPosition and ShapeObject.HorizontalPosition properties.
  • Set the text of WordArt using WordArt.Text property.
  • Set the fill color and stroke color of WordArt using ShapeObject.FillColor and ShapeObject.StrokeColor properties.
  • Save the document to another file using Document.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace CreatWordArt
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Document instance
            Document doc = new Document();

            //Add a section
            Section section = doc.AddSection();

            //Add a paragraph
            Paragraph paragraph = section.AddParagraph();

            //Append a shape to the paragraph and specify the shape size and type
            ShapeObject shape = paragraph.AppendShape(400, 150, ShapeType.TextDeflateBottom);

            //Set the position of the shape
            shape.VerticalPosition = 60;
            shape.HorizontalPosition = 60;
           
            //Set the text of WordArt
            shape.WordArt.Text = "Create WordArt in Word";

            //Set the fill color and stroke color of WordArt
            shape.FillColor = System.Drawing.Color.Cyan;
            shape.StrokeColor = System.Drawing.Color.DarkBlue;

            //Save the document
            doc.SaveToFile("CreateWordArt.docx", FileFormat.Docx2013);
        }
    }
} 

C#/VB.NET: Insert WordArt in Word

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.

Extract message contents in C#, VB.NET

2017-07-13 02:33:42 Written by Koohji

This article illustrates how to get message contents such as from address, send to address, subject, date and the body of the message by using Spire.Email.

Code snippets of how to extract the message contents:

Step 1: Load the mail message.

MailMessage mail = MailMessage.Load("Sample.msg");

Step 2: Create a new instance of StringBuilder.

StringBuilder sb = new StringBuilder();

Step 3: Get the message contents as we want.

//get the From address
sb.AppendLine("From:");
sb.AppendLine(mail.From.Address);

//get the To address
sb.AppendLine("To:");
foreach (MailAddress toAddress in mail.To)
{
    sb.AppendLine(toAddress.Address);
}

//get the date
sb.AppendLine("Date:");
sb.AppendLine(mail.Date.ToString());

//get the subject
sb.AppendLine("Subject:");
sb.AppendLine(mail.Subject);

//get the BodyText
sb.AppendLine("Message contents");
sb.AppendLine(mail.BodyText);

//get the BodyHtml
sb.AppendLine("BodyHtml");
sb.AppendLine(mail.BodyHtml);

Step 4: Write all contents in .txt

File.WriteAllText("ExtractMessageContents.txt", sb.ToString());

The extracted message contents in .txt file format.

Extract message contents in C#, VB.NET

Full codes:

[C#]
using Spire.Email;
using System.IO;
using System.Text;

namespace ExtractMessage 
{
    class Program
    {
        static void Main(string[] args)
        {

            MailMessage mail = MailMessage.Load("Sample.msg");

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("From:");
            sb.AppendLine(mail.From.Address);

            sb.AppendLine("To:");
            foreach (MailAddress toAddress in mail.To)
            {
                sb.AppendLine(toAddress.Address);
            }

            sb.AppendLine("Date:");
            sb.AppendLine(mail.Date.ToString());

            sb.AppendLine("Subject:");
            sb.AppendLine(mail.Subject);

            sb.AppendLine("Message contents");
            sb.AppendLine(mail.BodyText);

            sb.AppendLine("BodyHtml");
            sb.AppendLine(mail.BodyHtml);

            File.WriteAllText("ExtractMessageContents.txt", sb.ToString());
        }
    }
}
[VB.NET]
Dim mail As MailMessage = MailMessage.Load("Sample.msg")

Dim sb As New StringBuilder()

sb.AppendLine("From:")
sb.AppendLine(mail.From.Address)

sb.AppendLine("To:")
For Each toAddress As MailAddress In mail.[To]
	sb.AppendLine(toAddress.Address)
Next

sb.AppendLine("Date:")
sb.AppendLine(mail.[Date].ToString())

sb.AppendLine("Subject:")
sb.AppendLine(mail.Subject)

sb.AppendLine("Message contents")
sb.AppendLine(mail.BodyText)

sb.AppendLine("BodyHtml")
sb.AppendLine(mail.BodyHtml)

File.WriteAllText("ExtractMessageContents.txt", sb.ToString())

Send Bulk Emails in C#, VB.NET

2017-07-12 06:24:20 Written by Koohji

Sending bulk emails means that you can send a batch of emails to multiple recipients and they will not be able to determine the others you've sent the message to.

The following code snippets demonstrate how to send bulk emails using Spire.Email in C# and VB.NET.

Step 1: Create instances of MailMessage class and specify sender and recipients.

MailMessage message1 = new MailMessage("sender@e-iceblue.com", "recipient1@e-iceblue.com");
MailMessage message2 = new MailMessage("sender@e-iceblue.com", " recipient2@e-iceblue.com");
MailMessage message3 = new MailMessage("sender@e-iceblue.com", " recipient3@e-iceblue.com");

Step 2: Set the subject and body text of the messages.

message1.Subject = message2.Subject = message3.Subject = "Subject";
message1.BodyText = message2.BodyText = message3.BodyText = "This is body text.";

Step 3: Initialize an object of MailMessageCollection class and add the instances of MailMessage class into the object.

List msgs = new List();
msgs.Add(message1);
msgs.Add(message2);
msgs.Add(message3);

Step 4: Create a SmtpClient instance with host, port, username and password, and send batch of emails using SendSome method.

SmtpClient client = new SmtpClient();
client.Host = "smtp.outlook.com";
client.Port = 587;
client.Username = "sender@e-iceblue.com";
client.Password = "password";
client.ConnectionProtocols = ConnectionProtocols.Ssl;
client.SendSome(msgs);
Console.WriteLine("Message sent");

Full Code:

[C#]
MailMessage message1 = new MailMessage("sender@e-iceblue.com", "recipient1@e-iceblue.com");
MailMessage message2 = new MailMessage("sender@e-iceblue.com", " recipient2@e-iceblue.com");
MailMessage message3 = new MailMessage("sender@e-iceblue.com", " recipient3@e-iceblue.com");
message1.Subject = message2.Subject = message3.Subject = "subject";
message1.BodyText = message2.BodyText = message3.BodyText = "This is body text.";

List msgs = new List();
msgs.Add(message1);
msgs.Add(message2);
msgs.Add(message3);

SmtpClient client = new SmtpClient();
client.Host = "smtp.outlook.com";
client.Port = 587;
client.Username = "sender@e-iceblue.com";
client.Password = "password";
client.ConnectionProtocols = ConnectionProtocols.Ssl;
client.SendSome(msgs);
Console.WriteLine("Message sent");
[VB.NET]
Dim message1 As New MailMessage("sender@e-iceblue.com", "recipient1@e-iceblue.com")
Dim message2 As New MailMessage("sender@e-iceblue.com", " recipient2@e-iceblue.com")
Dim message3 As New MailMessage("sender@e-iceblue.com", " recipient3@e-iceblue.com")
message1.Subject = InlineAssignHelper(message2.Subject, InlineAssignHelper(message3.Subject, "subject"))
message1.BodyText = InlineAssignHelper(message2.BodyText, InlineAssignHelper(message3.BodyText, "This is body text."))

Dim msgs As New List(Of MailMessage)()
msgs.Add(message1)
msgs.Add(message2)
msgs.Add(message3)

Dim client As New SmtpClient()
client.Host = "smtp.outlook.com"
client.Port = 587
client.Username = "sender@e-iceblue.com"
client.Password = "password"
client.ConnectionProtocols = ConnectionProtocols.Ssl
client.SendSome(msgs)
Console.WriteLine("Message sent")
page 198