Spire.Doc
Thursday, 09 February 2012 02:49

How to Convert RTF to HTML in C#, VB.NET

Written by support iceblue

Spire.Doc allows users to use C#/VB.NET to convert RTF to HTML. And it's the same easy as conversion from Word to HTML. Now, follow the simple steps to use C#/VB.NET to convert RTF to HTML.

Note: Please make sure Spire.Doc and Visual Studio (Version 2008 or later) are correctly installed on your system.

Step 1: Create Project

Create a windows forms application project in your visual studio and add Spire.Doc dll as reference. Generate a button and double click to go to step 2.

Step 2: C#/VB.NET RTF to HTML Conversion

Spire.Doc offers an easy solution to convert RTF to HTML. Copy and paste the simple C# and VB.NET code into the project.

[C#]
            Document document = new Document();
            document.LoadFromFile(@"D:\Work\Stephen\2012.02.09\C# Create Excel.rtf");
            document.SaveToFile("sample.html", FileFormat.Html);
            WordDocViewer("sample.html");
[VB.NET]
Dim document As New Document()
document.LoadFromFile("D:\Work\Stephen\2012.02.09\C# Create Excel.rtf")
document.SaveToFile("sample.html", FileFormat.Html)
WordDocViewer("sample.html")

Step 3: Save and Preview

To fast preview the effect of RTF to HTML conversion, we can use the code below to save and start project.

[C#]
        private void WordDocViewer(string fileName)
        {
            try
            {
                System.Diagnostics.Process.Start(fileName);
            }
            catch { }
        }
[VB.NET]
Private Sub WordDocViewer(fileName As String)
	Try
		System.Diagnostics.Process.Start(fileName)
	Catch
	End Try
End Sub

Effective Screeshot:

Spire.Doc is a professional Excel component which enables developers/programmers to fast generate, read, write and modify Word document for .NET and Silverlight. It supports C#, VB.NET, ASP.NET, ASP.NET MVC and Silverlight.

Friday, 13 January 2012 02:29

Word Header in Silverlight

Written by support iceblue

The sample demonstrates how to add Word header in Silverlight via Spire.Doc.

 

Thursday, 08 December 2011 08:03

Protect Word with Specified Protection Type in C#

Written by support iceblue

Word Protection is a different from Word encryption. It allows users to open and view Word document but there are several permissions that users cannot edit or only can fill fields. Solution in this guide demonstrates solution to protect Word with specified protection type in C# and VB.NET with Spire.Doc for .NET. The following screenshot presents result after protecting with read-only.

Protect Word Document

Spire.Doc for .NET provides a method Document.Protect(ProtectionType type, String password) of Document class. There are five protection types offered.

No Protection: Sets document without protection.
AllowOnlyRevisions: Allows adding revision marks to Word.
AllowOnlyComments: Allows modifying comments in Word.
AllowOnlyFormFields: Allows entering data in form fields of Word.
AllowOnlyReading: Allows only reading Word.

The code below shows how to protect Word with AllowOnlyReading type. Download and install Spire.Doc for .NET and follow the code.

[C#]
using Spire.Doc;

namespace ProtectWord
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load Document
            Document document = new Document();
            document.LoadFromFile(@"E:\Work\Documents\.NET Framework.docx");
            //Protect Word
            document.Protect(ProtectionType.AllowOnlyReading, "123456");
            //Save and Launch
            document.SaveToFile("ProtectWord.docx");
            System.Diagnostics.Process.Start("ProtectWord.docx");        
        }
    }
}
[VB.NET]
Imports Spire.Doc

Namespace ProtectWord
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            'Load Document
            Dim document As New Document()
            document.LoadFromFile("E:\Work\Documents\.NET Framework.docx")
            'Protect Word
            document.Protect(ProtectionType.AllowOnlyReading, "123456")
            'Save and Launch
            document.SaveToFile("ProtectWord.docx")
            System.Diagnostics.Process.Start("ProtectWord.docx")
        End Sub
    End Class
End Namespace

Spire.Doc is a stand-alone component, enabling developers/programmers to generate, open, write, edit and save Word document in WPF, .NET and Silverlight without Microsoft Word installed on system.