How to set a document title in C# and .NET
If you are looking also for a .Net solution to Create or Modify HTML documents, see our Document .Net.
Complete code
using System;
using System.IO;
using System.Text;
namespace Sample
{
class Sample
{
static void Main(string[] args)
{
string inpFile = @"..\..\..\Images.rtf";
string outFile = @"..\..\..\Title.html";
SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();
SautinSoft.RtfToHtml.HtmlFixedSaveOptions opt = new SautinSoft.RtfToHtml.HtmlFixedSaveOptions
{
// Set document title, <title>...</title>
Title = "Here is the custom TITLE!",
// If you want to disable embedded images
EmbedImages = false,
// Set the folder to store images
ImagesDirectoryPath = @"..\..\..\Images",
// Set the folder in <image src="..." >
ImagesDirectorySrcPath = "Images"
};
try
{
r.Convert(inpFile, outFile, opt);
// Open the results for demonstration purposes.
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile)
{ UseShellExecute = true });
}
catch (Exception e)
{
Console.WriteLine($"Error: {e.Message}");
Console.WriteLine("Press any key ...");
Console.ReadKey();
}
}
}
}
Imports System
Imports System.IO
Imports System.Text
Namespace Sample
Friend Class Sample
Shared Sub Main(ByVal args() As String)
Dim inpFile As String = "..\..\..\Images.rtf"
Dim outFile As String = "..\..\..\Title.html"
Dim r As New SautinSoft.RtfToHtml()
Dim opt As New SautinSoft.RtfToHtml.HtmlFixedSaveOptions With {
.Title = "Here is the custom TITLE!",
.EmbedImages = False,
.ImagesDirectoryPath = "..\..\..\Images",
.ImagesDirectorySrcPath = "Images"
}
Try
r.Convert(inpFile, outFile, opt)
' Open the results for demonstration purposes.
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
Catch e As Exception
Console.WriteLine($"Error: {e.Message}")
Console.WriteLine("Press any key ...")
Console.ReadKey()
End Try
End Sub
End Class
End Namespace
If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below: